Skip to content

Conversation

leotaku
Copy link

@leotaku leotaku commented Sep 6, 2025

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: laravel/framework#52094

Output log
$ 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

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.

This ensures that no useless "Failed to poll event" error messages are
logged during normal server operation, as the SOCK_EAGAIN error simply
indicates another worker is already serving the request.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant