Home  >  Article  >  Backend Development  >  In PHP development, how to determine whether the previous script has finished running during scheduled execution?

In PHP development, how to determine whether the previous script has finished running during scheduled execution?

jacklove
jackloveOriginal
2018-05-22 14:36:421975browse

This article talks about how to determine whether the previous script has finished running during scheduled execution in PHP development?

In PHP development, sometimes we have such a requirement

A script is scheduled to be executed every two minutes. However, when the next script is executed in a loop, the previous script has not finished running. We should cancel the current script. Loop

So how to do it? There are many ways. Here I provide one that I think is more elegant

This is a test.php

<!--?php
echo 111;
sleep(1200);</pre-->

This is a shell script

test.sh

#!/bin/bash
process=`ps -ef|grep &#39;/Library/WebServer/Documents&#39;|grep -v grep|wc -l`
if [ $process -eq 0 ]
 then
php /Library/WebServer/Documents
else
echo "1111"
fi

I believe everyone can understand the meaning of the above script. It is nothing more than to judge if test.php is still When running, it outputs 111. You can change it to your own logic here.

You only need to execute it regularly./test.sh

This article explains in detail how to judge scheduled execution in PHP development. Whether the previous script has finished running, please pay attention to the php Chinese website for more related content.

Related recommendations:

The difference and use of const and static in php

The use of php and its regular expressions Detailed explanation

#How does PHP automatically load the two functions __autoload and apl_autoload_register?

The above is the detailed content of In PHP development, how to determine whether the previous script has finished running during scheduled execution?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn