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.