Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix unhelpful error messages with multiple PHP CLI workers #19737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
leotaku wants to merge 1 commit into php:PHP-8.3
base: PHP-8.3
Choose a base branch
Loading
from leotaku:polling-error-php8.3

Conversation

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
Reviewers
No reviews
Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /