xqterry
xqterry

Reputation: 652

php fpm requests queued

I use php 5.2.11 + php-fpm + nginx on my server. If a user sends a time consuming request "A", before getting response for "A" from the server, he sends more others normal requests. It is weird that user can not get any response before response for "A" returned, it seems php-fpm queues the requests. I checked tcp connection, the requests are sent from different socket, have same PHPSESSION. And on the server side, php-fpm also wrote the normal requests into slow log.

I can not figure out how to resolve it, any suggestions?

Upvotes: 5

Views: 1835

Answers (1)

iBobo
iBobo

Reputation: 724

It isn't PHP-FPM fault. Since you're saying they have the same session then that's the culprit. Sessions in PHP have a per-session lock, so one user cannot load a page with a specific session ID while there are outstanding requests with the same session; the blocking happens when you call session_start(). This is to avoid having different requests editing the same session variables (that causes all sort of problems). When a request ends and writes its resulting session data to the store, the next can start.

If you want to be able to read session variables and start a time consuming job, but don't want to block other requests from happening, just use session_write_close() after reading the session data you need to continue. Be aware that after calling that you cannot modify session data (and maybe you cannot read it because $_SESSION is emptied, but cannot remember).

Upvotes: 7

Related Questions