|
Posted by ED on 03/21/06 23:03
"JDS" <jeffrey@example.invalid> wrote in message
news:pan.2006.03.21.18.07.58.197413@example.invalid...
> Hi. I have installed the PCNTL functions[1] on my PHP enabled webserver
> in the interest of being able to fork a process into the background so I
> can do some heavy processing but return control of the browser back to the
> user rather quickly.
>
> However, after mucking about with PCNTL for a while and not getting the
> results I expected, I finally stumbled across this line in the opening
> parragraph on PCNTL functions on PHP.net:
>
> "Process Control should not be enabled within a webserver environment and
> unexpected results may happen if any Process Control functions are used
> within a webserver environment."
>
> Seems like they should bold and highlight in red that line, but I digress.
>
> In any case, can anyone suggest a way to fork a process off to unload a
> large amount of processing and return control of the web browser to the
> user? All the examples and whatnot I have found assume a CLI version of
> PHP. I want to do this on the web server!
>
> Thanks!!
>
>
>
>
>
> [1]I am running Apache2/PHP4.3 on RHEL 4. I downloaded the RPM for PCNTL
> at http://phprpms.sourceforge.net.
>
> --
> JDS | jeffrey@example.invalid
> | http://www.newtnotes.com
> DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/
>
Myabe a bit of a hack but one way is to make a http connection to the script
then immediately close it:
function forkHTTP($host, $script) {
$conn = @fsockopen($host, 80);
if ($conn) {
$cmd = "GET $script HTTP/1.1\r\n";
$cmd .= "Host: $host\r\n\r\n";
@fwrite($conn, $cmd);
@fclose($conn);
return true;
}
return false;
}
Just call the function to execute the process.
if (forkHTTP('www.mydomain.com', '/scripts/heavyprocess.php')) {
// OK - process called
} else {
//erm
}
HTH ED
Navigation:
[Reply to this message]
|