2015-11-14 13:22
浏览 30

在nginx / php-fpm配置上同时运行脚本的限制是什么?

The problem is I have to use curl and sometimes the curl requests take a long time because of the timeouts. I have set the timeouts to 1 second so no request should take more than 1 second but still the server is unable to process other php requests.

My question is how many concurrent scripts(running at the same time) can nginx/php-fpm handle. What I see is that a few requests lasting 1 second make the whole server unresponsive. What are the settings that I can change so more requests can be processed at the same time?

图片转代码服务由CSDN问答提供 功能建议

问题是我必须使用curl,有时由于超时,curl请求需要很长时间。 我已将超时设置为1秒,因此请求不应超过1秒,但服务器仍无法处理其他php请求。

我的问题是有多少并发脚本(运行于 同时)可以nginx / php-fpm处理。 我看到的是一些持续1秒的请求会使整个服务器无响应。 我可以更改哪些设置,以便同时处理更多请求?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwenyou4298 2015-11-28 14:37

    Php-curl did not respond in a timely manner because of DNS.

    The problem was that I had to access files from a CDN but the IP behind the domain changed frequently and unfortunately curl keeps a DNS cache.

    So from time to time it would try to access files from IPs that were not valid anymore, but they were still in the DNS cache of php-curl.

    I had to drop php-curl completely and use a plain file_get_contents(...) request. This completely solved the problem.

    打赏 评论
  • dongsha2792 2015-11-14 17:53

    Multicurl is indeed not the solution to your probleme, but asynchrousity probably is. I am not sure that the solution is tweaking Nginx. It would scale better if you were to consider one of the following options :

    • You can abstract Curl with Guzzle and use their approach to async call and promises.

    • You can use Gearmand http:/ which will enable you to send an async message to a remote server which will process the instruction based on a script you register to your message. (I use this mechanism for non blocking logging)

    Either way, your call will be made in milliseconds and won't block your nginx but your code will have to change a little bit.

    打赏 评论

相关推荐 更多相似问题