1

I’m running lighttpd 1.4.80 with PHP via FastCGI (php-cgi, not php-fpm).

The page Optimizing FastCGI performance says:

there is a potential race condition during the PHP cleanup code in which PHP can be shutting down but still have the socket open, so lighty can send request number 501 to PHP and have it "accepted", but then PHP appears to simply exit, causing a 500 return from lighty.
To limit this occurance, set PHP_FCGI_MAX_REQUESTS to 500.

From what I understand, this is about php-cgi exiting after handling PHP_FCGI_MAX_REQUESTS requests, and a race condition when the webserver sends another request just as PHP is shutting down.

Does this race condition still apply with current PHP versions (e.g. PHP 8.x) when using php-cgi with lighttpd 1.4.80?

Environment:

  • lighttpd 1.4.80

  • PHP 8.4

  • using php-cgi directly (FastCGI backends spawned by lighttpd)

I’m trying to understand whether the docs are describing a historical bug, or whether I still need to tune this setting today.

New contributor
noch is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • 1
    This sounds like a good question to whoever wrote that documentation (or at least to those who maintain it). But as it was already part of the documentation in 2008, I'd challenge whether it is really relevant anymore Commented 2 hours ago

1 Answer 1

0

As the lighttpd doc describes, this is (or was) a behavior of PHP. I have not looked in the PHP code, but if PHP is better about closing the socket as soon as it receives the last request to reach PHP_FCGI_MAX_REQUESTS rather than waiting until after the request has been handled, then maybe the race condition is smaller now than it once was.

Taking a step back, PHP_FCGI_MAX_REQUESTS was created by PHP due memory leaks which resulted in PHP processes using more and more memory over time, so the max requests was a knob to tell PHP to restart fresh.

If you monitor your system and things are running well, feel free to use a larger value for PHP_FCGI_MAX_REQUESTS.

I am a lighttpd developer (though I did not write that doc way back then), and the behavior your are asking about is all PHP-related, as I have described.

To answer your question directly: yes, you still need to tune this setting. Generically speaking, yes, you need to monitor your system. If on your system this is not an issue, then that is great! However, you need to monitor your system to determine that, and then set a value for PHP_FCGI_MAX_REQUESTS in lighttpd.conf, or, alternatives, in your php.ini.

https://www.php.net/manual/en/install.fpm.configuration.php

pm.max_requests int

The number of requests each child process should execute before respawning. This can be useful to work around memory leaks in 3rd party libraries. For endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. Default value: 0.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.