This article mainly introduces php's determination of program problems in linux, which can effectively control resource allocation during scheduled execution of crontab control programs in Linux, which is of great practical value, for more information about how to use php to identify program problems in linux, see the example in this article. Share it with you for your reference. The details are as follows:
Sometimes, when writing some scripts on the server, it is often necessary to put them in the crontab for regular operation. After a long time, there is a problem, that is, repeated running of the program consumes too much resources. how can this problem be solved? The following two methods are provided.
// Method 1: use the regular expression matching function ifrun ($ clsname, $ bf = 0) in linux {//. if a process is running, run $ str = shell_exec ("/bin/ps ax>/home/root /". $ clsname. "_run.txt"); $ str = shell_exec ("/bin/grep-C '". $ clsname. ". php '/home/root /". $ clsname. "_run.txt"); if ($ bf> 0) {if ($ str >=$ bf) {return 1 ;}else {return 0 ;}} else {if ($ str >=2) {return 1 ;}else {return 0 ;}}// call: if (ifrun ('poo', 5 )) {die ("pooy is running");} // note: Pooy is the name of the program pooy. php! // Type 2: write the process to the file, use the file function to read and match the string system ('PS-ef | grep wget>/root/pooy.txt '); $ arr = file ('/root/pooy.txt'); $ total = count ($ arr); for ($ I = 0; $ I <$ total; $ I ++) {$ count = array (); if (stristr ($ arr [$ I], 'www/pooy ')! = FALSE) {// echo '"earth" not found in string'; $ count [] = 'no'; break ;}} if (count ($ count)> = 1) {echo "A same programs are running"; exit () ;}else {echo "start __________________________________________________" ;}// note: "www/pooy" is a string contained in the program! // Is the php program running more smoothly in linux?
I hope this article will help you with php programming.