Is it possible to do an http direct when the child process of a fork has returned to the parent?
I tried doing:
header("Location: http://dev.mysite.com/invokefork.php?semaphoreid=".$semaphoreid."/");
This resulted in the error below, which is strange because there is nothing being echoed out when I'm running fork.php
from the terminal. This script is normally run by a call to exec()
within invokefork.php
PHP Warning: Cannot modify header information - headers already sent
Obviously I can't do an http redirect from the command line, I just wanted to see what would happen. When I tried running invokefork.php
from the browser it didn't do the redirect. The warning is present at the same line that the header()
call is on.
What want to do is have a background process which takes params and performs a search. While the search is being performed I'm thinking of redirecting to a "searching" page which checks the semaphore every 30 secs to see if it has been populated with data.
This should help understand a little more:
$pid = pcntl_fork();
if ($pid == -1) {
die("could not fork");
} elseif ($pid) {
pcntl_waitpid($pid, $status, WUNTRACED);
} else {
// emulate db/web service query.
sleep(10);
/*
Do webservice / database query here
When results return add them to shared memory
Redirect and pass semaphore id to so the data
from the semaphore can be looked up.
*/
header("Location: http://dev.globalgatewaydemo.com/invokefork.php?pid=".$pid."/");
}
Any ideas?