@@ -2529,6 +2529,14 @@ static zend_result php_cli_server_ctor(php_cli_server *server, const char *addr,
2529
2529
retval = FAILURE ;
2530
2530
goto out ;
2531
2531
}
2532
+ // server_sock needs to be non-blocking when using multiple processes. Without it, the first process would
2533
+ // successfully accept the connection but the others would block, causing client sockets of the same select
2534
+ // call not to be handled.
2535
+ if (SUCCESS != php_set_sock_blocking (server_sock , 0 )) {
2536
+ php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR , "Failed to make server socket non-blocking" );
2537
+ retval = FAILURE ;
2538
+ goto out ;
2539
+ }
2532
2540
server -> server_sock = server_sock ;
2533
2541
2534
2542
php_cli_server_startup_workers ();
@@ -2661,7 +2669,8 @@ static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, p
2661
2669
struct sockaddr * sa = pemalloc (server -> socklen , 1 );
2662
2670
client_sock = accept (server -> server_sock , sa , & socklen );
2663
2671
if (!ZEND_VALID_SOCKET (client_sock )) {
2664
- if (php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2672
+ int err = php_socket_errno ();
2673
+ if (err != SOCK_EAGAIN && php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2665
2674
char * errstr = php_socket_strerror (php_socket_errno (), NULL , 0 );
2666
2675
php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR ,
2667
2676
"Failed to accept a client (reason: %s)" , errstr );
0 commit comments