Re: Pass variable to pcntl_fork child

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



ipc can be used by shared memory, senaphore, queue, socket, unix domain socket etc.
variables should be shared copied to parent and child process both after fork.
u can store some variable at third party storage, like redid, and after that signal child process where u fetch it back.
And some other ipc means above u can try , too. 
-- 
helloworldjerry

开启 2014年7月2日 at 18:01:20, Uggla Henrik (henrik.uggla@xxxxxxxxxxxxxxx) 写:

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);  
}  


--  
PHP General Mailing List (http://www.php.net/)  
To unsubscribe, visit: http://www.php.net/unsub.php  


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux