Page 1 of 1

fsockopen - how to detect process completion?

Posted: Tue Oct 26, 2004 9:05 am
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

Posted: Tue Oct 26, 2004 2:10 pm
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()
}