I'm using the Symfony2 Process component to manually manage a pool of processes.
In the example below I restart 2 simple processes every 2 seconds and monitor what happens. The application breaks after restarting these processes a few hundred times.
Execution is stopped and I get the following PHP warning:
proc_open(): unable to create pipe Too many open files
and then the following exception is thrown by the Symfony Process component:
[Symfony\Component\Process\Exception\RuntimeException]
Unable to launch a new process.
I've manually monitored the total number of open processes and it never goes up the expected limit.
The below simplified snippet is part of a Symfony2 command and is being runned from the CLI (e.g. app/console hamster:run):
$processes[] = new Process("ls > /dev/null", null, null, null, 2);
$processes[] = new Process("date > /dev/null", null, null, null, 2);
while (count($processes) > 0) {
foreach ($processes as $i => $process) {
if (!$process->isStarted()) {
$process->start();
continue;
}
try {
$process->checkTimeout();
} catch (\Exception $e) {
// Don't stop main thread execution
}
if (!$process->isRunning()) {
// All processes are timed out after 2 seconds and restarted afterwards
$process->restart();
}
}
usleep($sleep * 1000000);
}
This application is being run on a MAC server running OS X 10.8.4.
I would appreciate any hints on how to pursue the root of this issue.
Update #1: I've simplified my function to work with basic commands like ls
and date
for faster testing. It still looks like the Process command fails after starting and stopping about 1000-1500 processes.
I suspected that proc_close()
was not being called correctly for each process, but further investigation revealed that's not the case here.