Skip to content

pavlelee/batch-result

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

#这个类可以很好的解决读取数据量非常大的需求,内存不至于溢出。

#使用方式

  • batch方式:
$batch = new BatchResult(function ($offset, $limit){
    //你自己的查询逻辑
    return $db->query("SELECT * FROM test LIMIT {$offset},{$limit}")->findAll();
});
$batch->batchSize = 2000;
$batch->each = false;

foreach ($batch as $items){
    foreach ($items as $item){
        echo $item['name'] . $item['id'] . "\r\n";
    }
}
  • each方式:
$batch = new BatchResult(function ($offset, $limit) use ($sysshop){
    //你自己的查询逻辑
    return $db->query("SELECT * FROM test LIMIT {$offset},{$limit}")->findAll();
});
$batch->batchSize = 2000;
$batch->each = true;

foreach ($batch as $item){
    echo $item['name'] . $item['id'] . "\r\n";
}

About

An batch get result class

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages