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;
  });
});
 
     
    