1

I am currently writing my first WordPress plugin.

If I now make a jquery ajax call on a click and call a php function, even if in this function is only sleep 10 and wp_die(), and I try during this to load the page in the frontend, the page loads only after the 10 seconds are over.

this call blocks the whole page at that moment. Why?

Here is my js

var data = {
  'action': 'my_export_retailer_import',
  'csv_file_path': csv_file_path
};

$.ajax({
  type: 'POST',
  url: ajaxurl,
  data: data,
  success: function(data){
}

});

Heres the PHP Function

add_action('wp_ajax_my_export_retailer_import', 'my_export_retailer_import', 30);

function my_export_retailer_import() {
sleep(10);
wp_die(); // this is required to return a proper result
};

// ----------

Edit: I have been able to identify the problem. When starting the website, there is a session_start() in the functions.php.

If I comment this out, all is well.

Fortunately, I don't actually need the session at that moment. Just a little redo in another function :-)

enky
  • 40
  • 8
  • 1
    Could it be that you are using PHP's built-in web server? If so, then I don't think it supports multiple concurrent requests by default. – Hendrik Feb 19 '21 at 07:48
  • Hi, thanks for the feedback. I have been able to identify the problem. When starting the website, there is a session_start() in the functions.php. If I comment this out, all is well. Fortunately, I don't actually need the session at that moment. EIn little rebuild I must nevertheless -_-,... – enky Feb 19 '21 at 07:56
  • 1
    Seems like related with that question - https://stackoverflow.com/questions/13772074/session-start-takes-very-long-time In the first answer - "`session_start` (with sessions stored in files) is blocking in PHP, so this issue will appear if you try to start several server sessions for the same browser session (AJAX or multiple browser tabs/windows). Each session_start will wait until the other sessions have been closed." – Hendrik Feb 19 '21 at 08:08

0 Answers0