0

I've got this PHP site that makes some hefty ajax calls. They take about 8-10 seconds and communicate with a lot of 3rd party APIs via cURL requests.

When these ajax calls are going on, the rest of the site is unresponsive. Not just this page, but another browser tab on another page all together.

what should I check to make sure PHP is able to fork multiple processes so the site doesn't hang?

PHP is run as PHP-fpm

location ~ \.php$ {
    fastcgi_pass   unix:/var/run/php5-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /var/www$fastcgi_script_name;
    fastcgi_buffers 256 64k;
    fastcgi_buffer_size 2400k;
    fastcgi_read_timeout 6000;
    uwsgi_read_timeout 6000;
    include fastcgi_params;
}

And nginx has enough worker procs

user www-data;
worker_processes 16;
pid /var/run/nginx.pid;

events {
   worker_connections 8000;
   multi_accept on;
}

Also, I've tested with sleep() and a long for loop. Both of those are fine. It seems just the cURL calls to external sites that cause the issue.

Not sure what's missing.

Thanks!

Sean Clark
  • 1,436
  • 1
  • 17
  • 31

1 Answers1

0

Sounds like you need to call session_write_close

PHP locks the session file when a script writes to the session, so each page has to wait for that one to finish executing before it can open the session (unless you call the above function after the write).

Say for example you have a long running Ajax process that writes to the session at the beginning. If you don't call session_write_close to tell PHP your script is done writing to the session, it will lock up the session for all other scripts until execution is complete.

developerwjk
  • 8,619
  • 2
  • 17
  • 33
  • So I think this is the answer, but I'm not sure how to place a fix. I can't just end the session early, I mean. I need code to run after this has finished. – Sean Clark Sep 05 '14 at 14:09
  • This is the final answer here, but ill mark it for you http://stackoverflow.com/questions/12315225/reopening-a-session-in-php – Sean Clark Sep 05 '14 at 14:31