This article mainly introduces php multi-task program instances. if you need a php multi-task program, you can refer to the following example to briefly parse the php multi-task program implementation method. the specific code is as follows:
<? Phperror_reporting (E_ALL); set_time_limit (0);/*** php multi-task program implementation * using proc_open * actually called process * can start multiple processes, you can use your imagination to do what you want to do, and then write a usable * if you are running php on linux and enabling the pcntl module, use the pcntl function to better **/class Thread {protected $ _ pref; // process reference protected static $ _ instance = null; protected $ _ pipes; private function _ construct () {$ this-> _ pref = 0;} public static function getInstance ($ file) {if (null = self: $ _ inst Ance) {self ::$ _ instance = new self;} $ descriptor = array (0 => array ("pipe", "r "), 1 => array ("pipe", "w"), 2 => array ("file ",". /error-output.txt "," a "),); self: $ _ instance-> _ pref = proc_open (" php-q $ file ", $ descriptor, self :: $ _ instance-> _ pipes); return true;} public function _ destruct () {proc_close ($ this-> _ pref ); $ this-> _ pref = null ;}// test code $ file = _ FILE __; if (empty ($ argv [1]) {$ t2 = T Hread: getInstance ("$ file 1"); $ t3 = Thread: getInstance ("$ file 2"); $ t4 = Thread :: getInstance ("$ file 3"); $ t5 = Thread: getInstance ("$ file 4"); $ t5 = Thread: getInstance ("$ file 5 "); $ t5 = Thread: getInstance ("$ file 6"); $ t2 = Thread: getInstance ("$ file 7"); $ t3 = Thread :: getInstance ("$ file 8"); $ t4 = Thread: getInstance ("$ file 9"); $ t5 = Thread: getInstance ("$ file 10 "); $ t5 = Thread: getInstance ("$ File 11"); $ t5 = Thread: getInstance ("$ file 12"); echo "Main thread done \ n ";} else {$ somecontent = "\ r \ n //~~~~~~~~~~~~ -The request number is :". $ argv [1]; sleep (mt_rand (0, 3); $ handle = fopen ($ file, 'A + '); fwrite ($ handle, $ somecontent );}