Page 1 of 1

fsockopen question

Posted: Sat Nov 13, 2004 9:24 am
by tomfra
I am using this code to execute one command:

Code: Select all

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

    fwrite($fp, $out);

    while (!feof($fp)){
      echo fgets($fp,32000); 
    }
This code works, it does indeed sends the GET request properly. But when I execute this code directly from the web browser, the "com=cache" command is beign processed in the real time just like if I executed it directly and not through fsockopen.

What I'd like to do is to 'force' the server to send the GET request, finish the job on the server and then notify me via email (for example) when the job is done. The reason for this is that the "cache" command can take several hours to finish.

I hope I explained it good enough... The point is, the work should be done "silently" on the server just like if the code was executed through Cron job.

Thanks!

Tomas

Posted: Sat Nov 13, 2004 10:17 am
by hedge
It sounds like you want it to run Asynchronously. You'd have to have your script submit a background job like a cron job or something of that nature.

Posted: Sat Nov 13, 2004 12:47 pm
by tomfra
But is there a way to create a new cron job or its alternative via PHP? I've heard something about the Pseudo Cron job class but that one is licenced under GPL which I can't combine with the script I am working on and I may not need all of its power either.

Tomas

Posted: Sat Nov 13, 2004 12:50 pm
by tomfra
On a similar note, is it possible to allow a given PHP script to be executed through Cron job only and not through web browser?

Tomas