Php scheduled task verification whether multiple processes call the same job method

Source: Internet
Author: User
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.

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.