GeneralBretch Posted March 19, 2009 Share Posted March 19, 2009 I've spent the best part of a couple of days playing with the pcntl_fork function but, whatever I try, it just doesn't seem to work for me. After trying it in my main project, and getting nowhere, I pared it down and am now testing with a very very simple script and even that doesn't work. I'm beginning to think that there may be a server setting preventing it from working but google has so far not yielded any answers, so I'm hoping this forum will. My script is below, followed by the output that appears in my log file. I've tried various approaches but the child processes never appear to die and the pcntl_wait() function just hangs forever. Has anyone seen this behaviour before and can anyone please provide a suggestion before I tear out what hair I have left. The script $logFile = fopen("/var/www/html/test.txt", "w"); $pid = pcntl_fork(); if ($pid == -1) { fwrite($logFile, "forking error\n"); } elseif ($pid) { fwrite($logFile, "In parent\n"); pcntl_wait($status); fwrite($logFile, "exit status:" . pcntl_wexitstatus($status) . "\n"); } else { fwrite($logFile, "In child ".getmypid()."\n"); sleep(5); exit(1); } fclose($logFile); The last output for this script was (and the processes have not died): In child 31747 In parent Quote Link to comment https://forums.phpfreaks.com/topic/150111-solved-forking-hell/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.