Socket Timeouts
| From: | Ilia A. | Date: | Fri, 02 Aug 2002 16:49:42 +0000 |
| Subject: | Socket Timeouts | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-86456@lists.php.net to get a copy of this message | ||
There is a problem with PHP in the way it currently handles opening of
connections to remote servers via php_streams. The problem can cause a PHP
script to sit a virtually forever inside a select() waiting for a response
from a remote server. This in turn causes an a webserver child, to become
effectively dead and if it happens enough times cause a denial of service.
This is particularly dangerous bug, since PHP scripts that open remote
files/resources are very common and those scripts can allow an attacker to
launch a trivially easy denial of service attack that would result in all of
the web servers threads/forks sitting on selects waiting on data from a
external source.
The solution to the problem is one line patch below, that sets the socket
timeout from unlimited to 10 seconds, thus preventing the problem I've
described above from happening.
main/network.c
511c511
< sock->timeout.tv_sec = -1;
---
> sock->timeout.tv_sec = 10;
Ilia
P.S.
If some of you do not feel comfortable with setting a static value for a
timeout, we can introduce a php.ini option allowing the admin to set a
different timeout value for sockets.