note 85687 modified in function.pcntl-fork by danbrown

From: Date: Tue, 10 Aug 2010 15:46:06 +0000
Subject: note 85687 modified in function.pcntl-fork by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-171537@lists.php.net to get a copy of this message
Here's one way to execute a bunch of commands in an array, each in its own process <?php foreach ($cmds as $cmd) { $pid=pcntl_fork(); if ($pid) { exec($cmd); break; } } ?> Don't forget the break statement! I use this in a cli routine to rip a bunch of internet radio streams in parallel. This kind of parallelism is natural here because the download rate for each stream is limited by the network, not the cpu. --was-- Here's one way to execute a bunch of commands in an array, each in its own process foreach ($cmds as $cmd) { $pid=pcntl_fork(); if ($pid) { exec($cmd); break; } } Don't forget the break statement! I use this in a cli routine to rip a bunch of internet radio streams in parallel. This kind of parallelism is natural here because the download rate for each stream is limited by the network, not the cpu. http://php.net/manual/en/function.pcntl-fork.php

« previous php.notes (#171537) next »