@@ -2499,6 +2499,14 @@ static zend_result php_cli_server_ctor(php_cli_server *server, const char *addr,
2499
2499
retval = FAILURE ;
2500
2500
goto out ;
2501
2501
}
2502
+ // server_sock needs to be non-blocking when using multiple processes. Without it, the first process would
2503
+ // successfully accept the connection but the others would block, causing client sockets of the same select
2504
+ // call not to be handled.
2505
+ if (SUCCESS != php_set_sock_blocking (server_sock , 0 )) {
2506
+ php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR , "Failed to make server socket non-blocking" );
2507
+ retval = FAILURE ;
2508
+ goto out ;
2509
+ }
2502
2510
server -> server_sock = server_sock ;
2503
2511
2504
2512
php_cli_server_startup_workers ();
@@ -2631,7 +2639,8 @@ static zend_result php_cli_server_do_event_for_each_fd_callback(void *_params, p
2631
2639
struct sockaddr * sa = pemalloc (server -> socklen , 1 );
2632
2640
client_sock = accept (server -> server_sock , sa , & socklen );
2633
2641
if (!ZEND_VALID_SOCKET (client_sock )) {
2634
- if (php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2642
+ int err = php_socket_errno ();
2643
+ if (err != SOCK_EAGAIN && php_cli_server_log_level >= PHP_CLI_SERVER_LOG_ERROR ) {
2635
2644
char * errstr = php_socket_strerror (php_socket_errno (), NULL , 0 );
2636
2645
php_cli_server_logf (PHP_CLI_SERVER_LOG_ERROR ,
2637
2646
"Failed to accept a client (reason: %s)" , errstr );
0 commit comments