douwen5985 2014-09-04 21:32
浏览 36
已采纳

PHP站点正在等待ajax调用完成

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!

  • 写回答

1条回答 默认 最新

  • dpc57092 2014-09-04 22:05
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog