PHP Threads class supports thread based tasks. The
<?PHP error_reporting(E_ALL); class dn extends Thread { public $res = ''; public $name = ''; public $runing = false; public $wfile; public function __construct($name) { $this->res = 'Running Fisrt Time ...\n'; $this->param = 0; $this->runing = true; $this->wfile = ""; } public function run() { while ($this->runing) { if ($this->param != "") { downloadurl($this->param,$this->wfile); $this->param = ''; } else { sleep(1); } } } } function downloadpages() { $webpath="http://www.endmemo.com/program/php/"; $pages = array("arraydiff","arraykeys","asort","ksort", "array","cookie","arraypush","copy","substr"); $wdir = "c:/test/"; $sticks[] = new dn('a'); $sticks[] = new dn('b'); $sticks[] = new dn('c'); $sticks[] = new dn('d'); $sticks[] = new dn('e'); foreach ($sticks as $w) { $w->start(); $w->param="w"; } $num = count($pages); for ($ii=0; $ii<$num;$ii++) { $wfile = $wdir . $pages[$ii] . ".htm"; $url = webpath . $pages[$ii] . ".php"; while (true) { foreach ($sticks as $worker) { if ($worker->param=='') { $worker->param = $url; $worker->wfile = $wfile; break 2; } } } } } function downloadurl($url, $wfile) { $res = file_get_contents($url); if (strlen($res)>10) { $newf = fopen ($wfile, "wb"); if ($newf) fwrite($newf,$res); fclose($newf); } } downloadpages(); ?>