Php multi-task program instance parsing _ php skills

Source: Internet
Author: User
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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.