How does popen implement multi-process concurrent execution? the pclose in the loop will wait for the process to complete and then perform the next loop.

Source: Internet
Author: User
1. how does PHPpopen implement concurrent execution of multiple processes? the pclose in the loop will wait until the process is completed and then perform the next loop. 2. suppose there are 17 processes to be enabled, how to start 5 processes each time, and shut down a process every time a process is completed, and start the next process at most... 1.PHP popen how to implement multi-process concurrent execution, the pclose in the loop will wait for the process to complete and then perform the next loop

2. suppose there are 17 processes to be enabled. how can we start five processes at a time, and shut down one process every time a process is completed, and start the next process at the same time? that is to say, only five processes can be executed at the same time.

// Start two processes for ($ I = 0; $ I <2; $ I ++) {$ command = "$ phpPath $ destPHPFile >>$ logFile $ I "; echo "process start time ". date ('Y-m-d H: I: s '). "\ n"; $ resource = popen ($ command, 'r'); if (is_resource ($ resource) {$ success ++; pclose ($ resource ); // the next loop will wait until the execution of the previous process is completed, and pclose will release the resource echo date ('Y-m-d H: I: s '). "process :". $ I. "The startup is complete, the execution is complete, and the next process \ n";} else {$ failure ++ ;}}

This method is equivalent to starting a process and executing it cyclically. it is equivalent to processing a task by a single process.

Reply content:

1. how does PHP popen implement concurrent multi-process execution? the pclose in the loop will wait for the process to finish and then perform the next loop.

2. suppose there are 17 processes to be enabled. how can we start five processes at a time, and shut down one process every time a process is completed, and start the next process at the same time? that is to say, only five processes can be executed at the same time.

// Start two processes for ($ I = 0; $ I <2; $ I ++) {$ command = "$ phpPath $ destPHPFile >>$ logFile $ I "; echo "process start time ". date ('Y-m-d H: I: s '). "\ n"; $ resource = popen ($ command, 'r'); if (is_resource ($ resource) {$ success ++; pclose ($ resource ); // the next loop will wait until the execution of the previous process is completed, and pclose will release the resource echo date ('Y-m-d H: I: s '). "process :". $ I. "The startup is complete, the execution is complete, and the next process \ n";} else {$ failure ++ ;}}

This method is equivalent to starting a process and executing it cyclically. it is equivalent to processing a task by a single process.

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.