fsockopen - how to detect process completion?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomfra
Forum Contributor
Posts: 126
Joined: Wed Jun 23, 2004 12:56 pm
Location: Prague, Czech Republic

fsockopen - how to detect process completion?

Post by tomfra »

I am using this code to create some cache files:

Code: Select all

$fp = fsockopen($domain, 80, $errno, $errstr);
    
    if (!$fp) {
      echo "$errstr ($errno)<br>\n";
		} else {
			
    $out = "GET ".$_SERVER['PHP_SELF']."?com=cache HTTP/1.1\r\n";
    $out .= "Host: $domain\r\n";
    $out .= "Connection: Close\r\n\r\n";

    fwrite($fp, $out);
   
    if ($res) { while (!feof($fp)) { echo fread($fp, 1024); }}    
    fclose($fp);
    }
It works great - it actually only executes another function via GET (?com=cache). My question is, is there a way how to detect the process has finished - e.g. send an email letting me know that all of the cache files have been created?

I suppose I can simply count the number of cache files with glob or something similar but that's not always the best idea (e.g. I'd have to delete all old cache files before executing this function etc.).

I haven't used fsockopen before so I may be missing something obvious.

As always, any ideas are welcome!

Tomas
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post by rehfeld »

not sure if this is what you mean, but could you just have the other script(the one your POSTing to) echo back something when it finishes?

then just check the results during the

while(!feof($fp))

bit to see if .

oh nevermind, just noticed your connection close header.

....cant just have the script the email you at the end of execution?

if (make_cache_files()) {
mail()
}
Post Reply