Why php5-fpm post requests are slow, while same php-cli code/console curl works extremely fast?

后端 未结 2 796
南方客
南方客 2021-02-04 03:22

I am performing POST request to local api web service (via LAN) with dummy method, that works very fast itself (less then a second).

Problem is that if i use php5-fpm it

2条回答
  •  滥情空心
    2021-02-04 03:41

    I just track down a similar issue of my own. I think it might be the same reason. I encounter the similar issue like avasin. I found that php-fpm curl to localhost is slow, but php-cli curl to localhost is extremely fast. Plus, debugging curl timing shows high starttransfer_time in php-fpm but rather low in php process.

    I found the root cause yesterday, the issue is the php-fpm www.conf config. Becuase php-fpm has low start_server, php-fpm actually has to process curl with limited number of php-fpm processes. The solution is to increase the number of start_server, this will affect the number of concurrency which your php-fpm could handle. The performance will decrease drastically when the concurrency exceeds the number of current php-fpm processes. Hence, making everything feels slow. The php-cli does not have the same issue since it could launch many php processes as long as you have enough memory, so it is always fast. I did a lot of experiments here php curl localhost is slow when making concurrent requests. Take a look if you're interested.

提交回复
热议问题