5066cd3969fcdd039792016b4981277b98a3091d
By:
strime

Long script blocks other requests in PHP-FPM / Nginx

January 28, 2016 2.6k views
Nginx PHP PHP Frameworks MySQL Ubuntu

Hi all,

I'm facing an issue I don't manage to resolve.
I have a PHP application which executes FFMPEG to convert videos. This script is quite long to execute because of FFMPEG conversion time.
The problem is, while this script is executing, all other requests sent to Nginx / PHP-FPM are waiting and don't execute, and I can't find the proper configuration to make this work.

In nginx.conf, I have this:

worker_processes 2;
worker_connections 768;
multi_accept on;
keepalive_timeout 65;

In PHP-FPM www.conf:

pm.max_children = 10

The application is developed with Symfony2.8 and you'll find below the typical error message I get, which is a MySQL timeout but digging a bit on the internet, I narrowed the problem to a server configuration issue:

SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction

Does any of you have any idea what could prevent requests to be executed when a PHP script is already running?

Thanks for your help,
Best regards,
Romain

1 comment
  • Ok, eventually ended up finding the solution.
    The problem is not related to Nginx / PHP-FPM blocking requests while a long running script is executed. It is due to the fact that the server only accepts a maximum number of simultaneous connections coming from the same browser. If you have ajax requests in your pages, it increases this number of connection. Trying to open the website in multiple tabs is then blocked.
    I've not found a solution yet to solve this problem, but at least I know that the other visitors are not impacted.

1 Answer

This question was answered by @strime:

Ok, eventually ended up finding the solution.
The problem is not related to Nginx / PHP-FPM blocking requests while a long running script is executed. It is due to the fact that the server only accepts a maximum number of simultaneous connections coming from the same browser. If you have ajax requests in your pages, it increases this number of connection. Trying to open the website in multiple tabs is then blocked.
I've not found a solution yet to solve this problem, but at least I know that the other visitors are not impacted.

View the original comment

  • Thanks Ryan for your answer.
    I ended up to the same conclusion than you but couldn't find a way to solve this problem.
    What I eventually did was to rewrite the way long running scripts were working in order to send a response to the ajax request right now and launch these scripts asynchronously.
    I was a must-have for our app in terms of performances anyway.
    Thanks for your help.

Have another answer? Share your knowledge.