note 51970 added to function.fsockopen
| From: | nospam at cronjob dot de | Date: | Sun, 17 Apr 2005 12:06:15 +0000 |
| Subject: | note 51970 added to function.fsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88108@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://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!
----
Manual Page -- http://www.php.net/manual/en/function.fsockopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+51970
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51970&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51970&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51970&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51970&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51970&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+51970&report=yes
Search -- http://master.php.net/manage/user-notes.php