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