[php-src] PR #19737: Fix unhelpful error messages with multiple PHP CLI workers
| From: | leotaku | Date: | Sat, 06 Sep 2025 12:45:12 +0000 |
| Subject: | [php-src] PR #19737: Fix unhelpful error messages with multiple PHP CLI workers | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-33112@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/19737
Author: leotaku
## Context
When the
PHP_CLI_SERVER_WORKERS environment variable is set to >=2, the PHP error
log contains a flood of error messages titled "Failed to poll event". It seems like more
service workers also increase the number and likelyhood of these messages.
This has previously been reported to the Laravel project, where they filter out this message from
their logs manually: https://github.com/laravel/framework/pull/52094
<details>
<summary>Output log</summary>
<pre>$ PHP_CLI_SERVER_WORKERS=10 php -S localhost:8080 index.php
[117756] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117757] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117758] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117759] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117760] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117761] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117762] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117763] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117755] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117764] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117765] [Sat Sep 6 13:48:43 2025] PHP 8.4.12 Development Server (http://localhost:8080) started
[117755] [Sat Sep 6 13:48:47 2025] [::1]:43226 Accepted
[117755] [Sat Sep 6 13:48:47 2025] [::1]:43226 Closing
[117755] [Sat Sep 6 13:48:50 2025] [::1]:38070 Accepted
[117757] [Sat Sep 6 13:48:50 2025] Failed to poll event
[117760] [Sat Sep 6 13:48:50 2025] Failed to poll event
[117755] [Sat Sep 6 13:48:50 2025] [::1]:38070 Closing
[117759] [Sat Sep 6 13:48:51 2025] [::1]:38084 Accepted
[117759] [Sat Sep 6 13:48:51 2025] [::1]:38084 Closing
[117759] [Sat Sep 6 13:48:52 2025] Failed to poll event
[117760] [Sat Sep 6 13:48:52 2025] Failed to poll event
[117757] [Sat Sep 6 13:48:52 2025] Failed to poll event
[117755] [Sat Sep 6 13:48:52 2025] [::1]:38092 Accepted
[117755] [Sat Sep 6 13:48:52 2025] [::1]:38092 Closing
[117757] [Sat Sep 6 13:48:53 2025] Failed to poll event
[117759] [Sat Sep 6 13:48:53 2025] Failed to poll event
[117763] [Sat Sep 6 13:48:53 2025] [::1]:38102 Accepted
[117763] [Sat Sep 6 13:48:53 2025] [::1]:38102 Closing
[117763] [Sat Sep 6 13:48:55 2025] Failed to poll event
[117759] [Sat Sep 6 13:48:55 2025] [::1]:38116 Accepted
[117757] [Sat Sep 6 13:48:55 2025] Failed to poll event
[117759] [Sat Sep 6 13:48:55 2025] [::1]:38116 Closing
[117759] [Sat Sep 6 13:48:56 2025] Failed to poll event
[117755] [Sat Sep 6 13:48:56 2025] Failed to poll event
[117763] [Sat Sep 6 13:48:56 2025] Failed to poll event
[117757] [Sat Sep 6 13:48:56 2025] [::1]:38118 Accepted
[117757] [Sat Sep 6 13:48:56 2025] [::1]:38118 Closing
</pre>
</details>
## My diagnosis
I think this happens because multiple workers will (correctly) poll on the same set of shared file
descriptors. As the workers get notified that a file descriptor is ready, they race to accept.
However, only the first worker will succeed, while others receive an EAGAIN error.
## My solution
My solution simply considers a socket callback getting an EAGAIN error as that callback
succeeding. I think this is fine, because I assume that the only way the accept call
would return this error code is because the request is already being handled by another worker. It
is possible that this assumption is incorrect, in which case a different solution would be required.
It would also be possible to simply remove or downgrade the "Failed to poll event" as
_real_ connection errors already get logged
[here](https://github.com/php/php-src/blob/366a5a2b37cb1c490ce35117711c1804168ca08f/sapi/cli/php_cli_server.c#L2716).