This article mainly introduces how php schedules a task to verify whether multiple processes call the same job. it involves php's usage tips for calling a process in a scheduled task, it has some reference value. if you need it, you can refer to the example in this article to describe how to verify that multiple processes call the same job in php. We will share this with you for your reference. The details are as follows:
When using scheduled tasks, the company once experienced two processes running the same scheduled task, resulting in many jobs being executed twice, to prevent this situation, you need to restrict the linux process. if a process is calling this scheduled task at the same time, the other process will not be allowed to call it again. The following is the specific code.
// $ Pro method name private function _ verifyPsAux ($ pro) {$ arrProcess = array ($ pro => "/usr/local/www/scrm/public/index. php/records/job/{$ pro} "); $ pidNumber = 0; foreach ($ arrProcess as $ key => $ value) {exec ("ps aux | grep '$ key'", $ return); $ isRunning = false; // The command does not execute foreach ($ return as $ k => $ v) {if (! Strrpos ($ v, $ value) continue; // preg_match ('/\ d +: \ d ++ \/usr/iu', $ v, $ match ); // if (! Isset ($ match [0]) continue; $ isRunning = true; $ pidNumber ++;} // if the current process exists, terminate if ($ isRunning & $ pidNumber> 1) {echo '[_'. date ('Y-m-d H: I: s '). "_] The process is running \ n"; exit ();}}}
I hope this article will help you with php programming.