开发者

Checking whether or not a script is running on Apache via PHP

I need to check whether or not an administrative script is already running on Apache, if not then it runs. Currently, I'm loading the server-status contents and checking against it but if I'm checking whether or not the current script is already running it will always return true because I'm running the script to check on itself. Does that make sense?

Basically in "script.php" is something like:

if($this_is_already_running) { exit; }
else { run it }

but 开发者_开发百科it is currently running while it checks on itself so it will always return true.

Any help is greatly appreciated.


I would use a lock file. Your script would write a file into a pre-defined location, and lock it. Additional instances of your script would check the lock, and if it is in place, exit.

See flock()

the manual has some good examples.


What about getting the script's PID?

Here's a class for it: http://www.electrictoolbox.com/check-php-script-already-running/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜