note 51970 modified in function.fsockopen by danbrown

From: Date: Mon, 18 May 2009 01:55:27 +0000
Subject: note 51970 modified in function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155610@lists.php.net to get a copy of this message
Be careful if you open a lot of sockets in one php-file! I had a script which checked a lot of domains and opened sockets to the whois-server. Even that I closed the connections after I checked a domain (fclose), the sockets seemed to stay open. After a while (about 1000 connections) the php-script couldn't open any more sockets. It took a while to fix this problem. I did this by writing a script which started the check-scripts with wget (or lynx). I started 5 scripts parallel and just checked 20 domains. After that new 5 scripts where opened. That helped me not to open too many sockets in one php-file because when a php-script ends, all open sockets are closed. Example: start.php: <?php ignore_user_abort(true); for($i=0; $i<100; $i++) { echo $i."- "; flush(); $exec_string = 'lynx http://example.com/whois.php &'; $output = $exec_string; sleep(10); $exec_string = 'killall lynx'; $output = $exec_string; } ?> whois.php: <?php ignore_user_abort(true); for($i=0; $i<50; $i++) { fsockopen(whois.server...); // here you process the whois-things } ?> Hope this'll help some people! --was-- Be careful if you open a lot of sockets in one php-file! I had a script which checked a lot of domains and opened sockets to the whois-server. Even that I closed the connections after I checked a domain (fclose), the sockets seemed to stay open. After a while (about 1000 connections) the php-script couldn't open any more sockets. It took a while to fix this problem. I did this by writing a script which started the check-scripts with wget (or lynx). I started 5 scripts parallel and just checked 20 domains. After that new 5 scripts where opened. That helped me not to open too many sockets in one php-file because when a php-script ends, all open sockets are closed. Example: start.php: <?php ignore_user_abort(true); for($i=0; $i<100; $i++) { echo $i."- "; flush(); $exec_string = 'lynx http://domain.tld/whois.php &'; $output = $exec_string; sleep(10); $exec_string = 'killall lynx'; $output = $exec_string; } ?> whois.php: <?php ignore_user_abort(true); for($i=0; $i<50; $i++) { fsockopen(whois.server...); // here you process the whois-things } ?> Hope this'll help some people! http://php.net/manual/en/function.fsockopen.php

« previous php.notes (#155610) next »