2014-09-04 21:32



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/;

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.


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dpc57092 dpc57092 7年前

    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.

    点赞 评论 复制链接分享