親pidにある配列要素を変更できるようにしたい。コード例を次に示します。
$arrayContainer = array(
array(
"id" => 1,
"name" => "Lenny"
),
array(
"id" => 2,
"name" => "Dudley"
),
array(
"id" => 3,
"name" => "Simon"
),
);
foreach ($arrayContainer as $key => $element) {
$pid = pcntl_fork();
if($pid == -1) {
// Something went wrong (handle errors here)
die("Could not fork!");
} elseif($pid == 0) {
$arrayContainer[$key]['size'] = 123;
$arrayContainer[$key]['fileName'] = 'somefile.txt';
// The child dies after a short while, becoming a zombie
exit();
} else {
// This part is only executed in the parent
}
}
したがって、このスクリプトが終了すると、子プロセスに記述した 2 つの要素は foreach ループの最後にはありません。親pidにある配列を子から変更できません。理由はわかりますが、それを可能にする素晴らしい解決策が思いつきません。何か提案できますか?グローバルか何か?