0

I need to add nearly 1000 records from my plugin. 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.

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. 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. And the number of insertions vary with each execution .

I'm using AJax to process it. The code is given below. Is the cause lied in 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;
  });

});
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
wblteam
  • 53
  • 2
  • 10
  • May be ajax get timeout when it takes time ? try using ajax instead of post with async false http://stackoverflow.com/questions/1478295/what-does-async-false-do-in-jquery-ajax and perform the function 10 per request of ajax to make it ajax continuously runs up – Vignesh Pichamani Jan 07 '15 at 11:02

1 Answers1

0

How much time does it run before it fails? It could be that you're hitting PHP's limits of execution time or memory. You can add these two lines at the beginning of PHP code to try it:

// 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');
Nenad Mitic
  • 577
  • 4
  • 12