@@ -2438,6 +2438,14 @@ static int php_cli_server_ctor(php_cli_server *server, const char *addr, const c
2438
2438
retval = FAILURE ;
2439
2439
goto out ;
2440
2440
}
2441
+ // server_sock needs to be non-blocking when using multiple processes. Without it, the first process would
2442
+ // successfully accept the connection but the others would block, causing client sockets of the same select
2443
+ // call not to be handled.
2444
+ if (SUCCESS != php_set_sock_blocking (server_sock , 0 )) {
2445
+ php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR , "Failed to make server socket non-blocking" );
2446
+ retval = FAILURE ;
2447
+ goto out ;
2448
+ }
2441
2449
server -> server_sock = server_sock ;
2442
2450
2443
2451
php_cli_server_startup_workers ();
@@ -2578,7 +2586,8 @@ static int php_cli_server_do_event_for_each_fd_callback(void *_params, php_socke
2578
2586
struct sockaddr * sa = pemalloc (server -> socklen , 1 );
2579
2587
client_sock = accept (server -> server_sock , sa , & socklen );
2580
2588
if (!ZEND_VALID_SOCKET (client_sock )) {
2581
- if (php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2589
+ int err = php_socket_errno ();
2590
+ if (err != SOCK_EAGAIN && php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2582
2591
char * errstr = php_socket_strerror (php_socket_errno (), NULL , 0 );
2583
2592
php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR ,
2584
2593
"Failed to accept a client (reason: %s)" , errstr );
0 commit comments