ID: 41291 Updated by: [EMAIL PROTECTED] Reported By: fmajid at kefta dot com -Status: Assigned +Status: Closed Bug Type: CGI related Operating System: Solaris PHP Version: 5.2.2 Assigned To: dmitry New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2007-05-04 19:13:18] fmajid at kefta dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41291&edit=1