当fork的子进程返回父进程时,是否可以执行http直接?
我尝试过:
header("Location: http://dev.mysite.com/invokefork.php?semaphoreid=".$semaphoreid."/");
这导致了下面的错误,这很奇怪,因为当我从终端运行fork.php
时没有任何回声。此脚本通常通过exec()
invokefork.php
调用来运行
PHP Warning: Cannot modify header information - headers already sent
显然我不能从命令行执行http重定向,我只想看看会发生什么。当我尝试从浏览器运行invokefork.php
时,它没有进行重定向。警告出现在header()
呼叫所在的同一行。
想要做的是有一个后台进程,它接受参数并执行搜索。正在执行搜索时,我正在考虑重定向到“搜索”页面,该页面每隔30秒检查一次信号量,看看是否已经填充了数据。
这应该有助于理解更多:
$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."/");
}
有什么想法吗?