dpsfay2510 2019-02-01 13:42
浏览 56

为什么我的脚本在几千个条目后停止插入数据库?

I want to insert around 200k entries (several calculated booking dates for each user) into my MySQL database table with a PHP script. But although my script keeps on running, the database stops adding the entries (usually around 80k-85k entries / ~10MiB). Why? And how can I make it work?

The actual Database operations happen in a booking-management-system class (using mysqli prepared statements), from which I call the main method in a loop for every user. I maxed out the execution time via ini_set('max_execution_time', 0) and ini_set('mysql.connect_timeout', 0) as well as the server memory limit ini_set('memory_limit', '812M') so the script and the server itself are not failing.

If I split up the number of user (which get their entries calculated) the inserts work just fine, so there's no limitation on the database site either.

My best guess is that there is some sort of memory/cache/buffer for insert-operations running full, that I'm unaware of. Does this make sense? If so, how can I deal with this kind of memory management? Or what else could be responsible?

Thank you in advance for your replies.

Edit after comments: Here is my code. Unfortunately, I can't post every method in my class that performs the database operations, but they all are prepared statements that throw exceptions, when the execute() of the query fails. I get neither errors nor exceptions. The script just keeps running, but the table rows aren't adding.

// Initialisation
...
ini_set('display_errors', '1');
ini_set('error_reporting', E_ERROR || E_WARNING);
ini_set('memory_limit', '812M');
ini_set('max_execution_time', 60000);
ini_set('mysql.connect_timeout', 0);

try{
    $select = $mysqli->prepare("SELECT id FROM customers WHERE dept = ?");
    $depts = array(24, 25, 29, 36, 93, 163, 108, 181);
    foreach($depts as $id){
         $select->bind_param('i', $id);
         if($select->execute()){
             $result = $select->get_result();
             while($row = $result->fetch_object()){
                 $system->customerBooking($row->id);
             }
             $result->free();
         } else {
             echo '<br/>'.$select->error;
         }
    }
} catch(Exception $e){
    var_dump($e);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP