Example of using php to guard another php process and guarding another php process _ PHP Tutorial

Source: Internet
Author: User
The example of using php to guard another php process and to guard another php process. An example of using php to guard another php process. to guard another php process, use php to guard another php process (except for running the apache module and nginx). php needs to guard B. p: an example of using php to guard another php process.

Use php to guard another php process (except for running the apache module and nginx)
A. php should guard B. php

In B. php, use the getmypid () function to obtain the id of the current process and write the id to the c. pid file. if the program is executed, delete or clear the c. pid file.

In. verify c. whether the pid exists and is empty. if not, read the pid and execute ps-p pid | grep file name through exec to determine whether the pid is running. then, execute the corresponding operation.

Someone may ask why the ps aux | grep file name is not directly used. this is mainly because the file name is duplicated.

A. php code

The code is as follows:


<?
$ Id = intval ($ argv [1]);
If (! File_exists ('pid '. $ id.'. pid ')){
Echo "not run ";
Exit;
}
$ Content = file_get_contents ('pid '. $ id.'. pid ');
If (empty ($ content )){
Echo "not run ";
Exit;
}
Exec ("ps p". $ content. '| grep B. php', $ pids );
If (count ($ pids)> 0) echo ('runing ');
Else {echo 'not run ';}
?>


B. php code

The code is as follows:


<?

$ Id = intval ($ argv [1]);
If (empty ($ id) exit;
File_put_contents ('pid '. $ id.'. pid ', getmypid ());
While (1 ){
File_put_contents ('pid '. $ id.'. pid ', getmypid ());
Sleep (100 );
}
?>

Ghost should use php to guard another php process (except for running the apache module and nginx). a. php should guard B. p...

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.