|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2007-05-10 15:22 UTC] dmitry@php.net
 | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
Description: ------------ The CGI/FastCGI SAPI does not set the SO_REUSEADDR option. This can prevent the FastCGI server from being restarted if it exits with sockets in the TIME_WAIT state. The patch below fixes this. That said, a much better option would be to refactor the fastcgi.c code to use php_network_bind_socket_to_local_addr instead of reinventing the square wheel. *** php-5.2.1/sapi/cgi/fastcgi.c~ Mon Jan 1 01:36:12 2007 --- php-5.2.1/sapi/cgi/fastcgi.c Fri May 4 11:45:39 2007 *************** *** 253,258 **** --- 253,261 ---- int listen_socket; sa_t sa; socklen_t sock_len; + #ifdef SO_REUSEADDR + int val = 1; + #endif if ((s = strchr(path, ':'))) { port = atoi(s+1); *************** *** 308,313 **** --- 311,319 ---- /* Create, bind socket and start listen on it */ if ((listen_socket = socket(sa.sa.sa_family, SOCK_STREAM, 0)) < 0 || + #ifdef SO_REUSEADDR + setsockopt(listen_socket, SOL_SOCKET, SO_REUSEADDR, (char*)&val, sizeof(val)) < 0 || + #endif bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 || listen(listen_socket, backlog) < 0) { Reproduce code: --------------- Run a FastCGI web server and start the FastCGI SAPI using php -b. Kill the FastCGI process. Attempt to restart it. Expected result: ---------------- FastCGI server restarting normally Actual result: -------------- alamut ~>php-cgi -b 127.0.0.1:8888 -c /home/majid/web/conf Cannot bind/listen socket - [125] Address already in use. Couldn't create FastCGI listen socket on port 127.0.0.1:8888