简体   繁体   English

$ wpdb-> insert:添加多个记录时出现问题(近1000个)

[英]$wpdb->insert : problems adding multiple records ( nearly 1000)

I need to add nearly 1000 records from my plugin. 我需要从插件添加近1000条记录。 While trying sometimes I have not all records are added. 虽然有时我没有所有记录都添加。 Also the number of records varies. 记录数也有所不同。 Sometimes it is 300 , sometimes it is 400 , sometimes it is 200 etc. 有时是300,有时是400,有时是200等。

Initial query was: 最初的查询是:

foreach ($data as $value) {
  $success=$wpdb->insert( 
    $table, 
    array( 
      'url' => $value, 
      'status' => 'n',
    ), 
    array( 
      '%s', 
      '%s' 
    ) ); 
}

I though some problems maybe with $value . 我虽然$value可能有一些问题。 Then to test I tried with the following: 然后,为了进行测试,我尝试了以下操作:

for($i=1;$i <= 1000;$i++){ 
  $success=$wpdb->insert( 
    $table, 
    array( 
      'url' => $i, 
      'status' => 'n',
    ), 
    array( 
      '%s', 
      '%s' 
    ) ); 
 }

It is also behaving the same. 它也表现相同。 Sometimes not 1000 records get added. 有时不会添加1000条记录。 And the number of insertions vary with each execution . 并且插入次数随每次执行而变化。

I'm using AJax to process it. 我正在使用AJax对其进行处理。 The code is given below. 代码如下。 Is the cause lied in Ajax. 原因在于Ajax。


jQuery(document).ready(function($) {

  jQuery('#sbswp').submit( function (event){

    var data = {
      'action': 'sbi2wp_action',
      url : $('input[name=url]').val(),
    };

    $.post(ajaxurl, data, function(response) {
      $('#result').html(response);
    });
    return false;
  });

});

How much time does it run before it fails? 它运行多少时间才能失败? It could be that you're hitting PHP's limits of execution time or memory. 可能是您达到了PHP的执行时间或内存限制。 You can add these two lines at the beginning of PHP code to try it: 您可以在PHP代码的开头添加以下两行来进行尝试:

// allows php script to run for 3000 seconds before it's terminated
ini_set('max_execution_time', 3000);

// allows php to use up to 512 megabytes of RAM
ini_set('memory_limit', '512M');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM