私の問題はこれです。ディスク上のファイルへのアクセス時間を短縮できるように、プロセスをフォークしています。これらのファイルのデータはすべて、ローカル デスクの tmp ファイルに保存します。理想的には、すべてのプロセスが完了したら、その tmp ファイルにアクセスして、そのデータを配列に取得する必要があります。次に、不要になった tmp ファイルのリンクを解除します。私の問題は、すべての子プロセスが完了するまで pcntl_wait() が実際には待機していないように見えることです。そのため、ランダムなプロセスが完了する前に、そのファイルのリンクを解除してしまいます。
すべてのプロセスが正常に終了し、データにアクセスするのを待つ確実な方法を見つけることができないようです。
$numChild = 0;
$maxChild = 20; // max number of forked processes.
// get a list of "availableCabs"
foreach ($availableCabs as $cab) {
// fork the process
$pids[$numChild] = pcntl_fork();
if (!$pids[$numChild]) {
// do some work
exit(0);
} else {
$numChild++;
if ($numChild == $maxChild) {
pcntl_wait($status);
$numChild--;
}
} // end fork
}
// Below is where things fall apart. I need to be able to print the complete serialized data. but several child processes don't actually exit before i unlink the file.
$dataFile = fopen($pid, 'r');
while(($values = fgetcsv($dataFile,',')) !== FALSE) {
$fvalues[] = $values;
}
print serialize($fvalues);
fclose($dataFile);
unlink($file);
問題ではない投稿が必要な場合は、実際に行っていることに関して多くのコードを省略していることに注意してください。