我有一个非常慢的脚本需要经常执行(一分钟约30次),因此用户无法执行它,并且cron作业最多每分钟运行一次。
那么,有没有办法(使用PHP)让服务器工作而不是用户?
答案 0 :(得分:2)
这很简单:使用标记文件
脚本在没有用户交互的情况下运行(可以由cron或shell启动,包括PHP shell执行):
<?php
while (true) {
while (file_exists('/path/to/flagfile')) sleep(1); //Can even use microsleep
include ('/path/to/worker/script');
touch('/path/to/flagfile');
}
?>
触发它的脚本(通过用户交互从网络服务器启动)
<?php
@unlink('/path/to/flagfile');
echo "Processing triggered!";
?>