开发者

Windows Bat check if php script runnin

开发者 https://www.devze.com 2023-03-04 22:05 出处:网络
I am using a bat to run a php on win2003 scheduler. Is there a way to check the proc开发者_高级运维esses and see if the file is still running.How about your batch file like this: (pseudocode, as it\'s

I am using a bat to run a php on win2003 scheduler. Is there a way to check the proc开发者_高级运维esses and see if the file is still running.


How about your batch file like this: (pseudocode, as it's been a while)

:makerandom
make som random var, microtime, whatever, we call it %x%
check if file exist, if it does, goto makerandom
call the script with %x% as argument
:check
if file exist %x% goto check
:done

in the php-script:

create the file specified by the argument
... script here ...
delete the file


In your scheduled task's .php file: Use getmypid() to get the PHP process' ID (PID) and save it to a file.

Next time your .php file is called, use $tasks = shell_exec('tasklist.exe'); to get a list of all active processes, then read the previously saved PID and look it up.

Honestly, I don't know if this is the best solution or not.


Try out Sysinternals Process Utilities.

http://technet.microsoft.com/en-us/sysinternals/bb896682

The pslist utility is just what you need (given a pid tells if it's running setting an env variable)

Regards

PS: with pslist I suggest evaluating also the pskill utility

0

精彩评论

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