Re: Re: Run a php script as a separate thread/process

From: Date: Thu, 13 Oct 2005 18:13:50 +0000
Subject: Re: Re: Run a php script as a separate thread/process
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-224079@lists.php.net to get a copy of this message
On Wed, October 12, 2005 10:23 am, cc wrote: > On 10/12/05, Tommy Jensehaugen <tommy_jensehaugen@hotmail.com> wrote: >> Thank you very much. This is what I ended up with if anyone needs >> it: >> >> <?php >> function runSeparateThread($strHost, $strPath="/") { >> $fFile = fsockopen($strHost, 80, $intError, $strError); >> if ($fFile) { >> $out = "GET ".$strPath." HTTP/1.1\r\n"; >> $out .= "Host: ".$strHost."\r\n"; >> $out .= "Connection: Close\r\n\r\n"; >> if(!fwrite($fFile, $out)){ >> $result = "runSeparateThread():fwrite(). Could not >> write:'".$out."'. >> Host:'".$strHost."'. Path:'".$strPath."'"; >> } else { >> $result = true; >> } >> fclose($fFile); >> } else { >> $result = "runSeparateThread():fsockopen(): Could not connect to >> ".$strHost." (".$intError.") ".$strError."."; >> } >> return $result; >> } >> ?> I missed the original question... One thing to consider would be to have a list of hosts/urls you want, and to open up all the sockets non-blocking, and then loop through each socket and fread() data in a convenient-sized chunk and snag it. This will make all the remote computers run "in parallel" to some degree. This is most useful if the GETs you are doing are dynamic and take awhile for the remote server to generate the output. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#224079) next »