From: fmajid at kefta dot com
Operating system: Solaris
PHP version: 5.2.2
PHP Bug Type: CGI related
Bug description: FastCGI does not set SO_REUSEADDR
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 bug report at http://bugs.php.net/?id=41291&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41291&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41291&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41291&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41291&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41291&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41291&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41291&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41291&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41291&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41291&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41291&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41291&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41291&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41291&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41291&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41291&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41291&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41291&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41291&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41291&r=mysqlcfg