Re: Pass variable to pcntl_fork child
| From: | louis | Date: | Thu, 03 Jul 2014 03:45:53 +0000 |
| Subject: | Re: Pass variable to pcntl_fork child | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-323602@lists.php.net to get a copy of this message | ||
Child process should has the same environment as the parent process. I don't see any thing wrong with your code.
I assume that you are using php to handle http request for the using of $_GET , but I think it is wrong to use multi process in PHP in the HTTP SERVER environment
于 2014年07月02日 17:40, Uggla Henrik 写道:
Hi! I've tried the following code but the $call variable is not available in the pcntl_fork child. Searching the web, I've found posts that claim that all variables defined before pcntl_fork are copied to the child. I've also found posts that claim that no variables are passed/copied to the child. So, which of them is true and how should I correct my code to make it work? regards Henrik$call = str_replace('@@', '&', $_GET['call']);if ($pid = pcntl_fork()) { $previousCalls=file("calls.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); if (!in_array($call, $previousCalls)) { file_put_contents("calls.txt", $call."\n", FILE_APPEND); } } else { function displayUrl($url) { $ch = curl_init($url); curl_setopt ( $ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $curlResult = curl_exec($ch); curl_close($ch); list($headers,$content) = explode("\r\n\r\n",$curlResult,2); foreach (explode("\r\n",$headers) as $hdr) { if ($hdr != 'Transfer-Encoding: chunked') { header($hdr); } } echo $content; } displayUrl($call); }