开发者

How to run a .php file over and over...cron perhaps?

I have a php file that calls exec() on a c++ exe.When the .exe is finishing running I need to run the php file again,repeat .

I am wondering what is the best way to do this? This .php file has no user interaction 开发者_如何学运维and needs to be completely automated.

EDIT:Found another solution that would kill the process if it is already running which will cover this issue well.See posts on this page.

http://php.net/manual/en/function.getmypid.php


Here's a simple Linux line that starts up the script in the background and uses the watch command to restart the script whenever it finishes running:

watch -n 0 php /path/to/script.php &

Once you've started it like this, you can use the ps command to list running processes and find the process ID for watch, and then use kill process_id to stop watch.

It's probably not best practice to run commands like this, but it's a quick and easy solution that doesn't require any special access privileges on the system (whereas using cron might), and doesn't involve editing your code (whereas a codeigniter solution will).


I haven't used codeigniter before but there seems to be a solution as described in the wiki.

Depending on how you can access the system (if you are admin or not) and depending on how you are planning to update the automated commands, IMHO, you could use both solution (Linux crontab or codeigniter cron script).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜