note 44476 added to function.pfsockopen
| From: | greyatgreywyverndotmoc at osu1 dot php dot net | Date: | Sat, 07 Aug 2004 04:06:04 +0000 |
| Subject: | note 44476 added to function.pfsockopen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74127@lists.php.net to get a copy of this message | ||
pfsockopen is useful for having scripts executing others in the background.
I'm writing an intra-site search engine with spidering capabilities. To spider a ~200 page
site and index all the text takes about 60 seconds. Because I don't want the user waiting 60s
for the script to finish and thinking it's timing out, I use pfsockopen to have the server open
an HTTP connection with itself to execute the script in the background. Once the spidering is done,
the connection is closed without capturing the HTTP response. The output isn't important, the
spidering is!
I just make the script execute the following:
<?php
$st = pfsockopen($_SERVER['HTTP_HOST'], 80, $erstr, $errno, 5);
fwrite($st, "GET {$_SERVER['PHP_SELF']}?$key HTTP/1.0\r\nHost:
{$_SERVER['HTTP_HOST']}\r\n\r\n");
?>
Where $key is the QUERY_STRING trigger which starts the spidering process. This script is executed
in the background while the main script is free to finish loading and display a message like:
"The database is being reindexed, please wait."
BTW, I set a flag in another MySQL table which prevents searches while the spider is crawling.
----
Manual Page -- http://www.php.net/manual/en/function.pfsockopen.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44476
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44476&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44476&report=yes
Search -- http://master.php.net/manage/user-notes.php