不要忘记将最大执行时间设置为无限(0).
如果这是你的意图,那么最好确保你不要运行多个实例:
- ignore_user_abort(true);//if caller closes the connection (if initiating with cURL from another PHP,this allows you to end the calling PHP script without ending this one)
- set_time_limit(0);
- $hLock=fopen(__FILE__.".lock","w+");
- if(!flock($hLock,LOCK_EX | LOCK_NB))
- die("Already running. Exiting...");
- while(true)
- {
- //avoid cpu exhaustion,adjust as necessary
- usleep(2000);//0.002 seconds
- }
- flock($hLock,LOCK_UN);
- fclose($hLock);
- unlink(__FILE__.".lock");
如果在CLI模式下,只需运行该文件.
如果在Web服务器上的另一个PHP中,您可以启动必须像这样运行的那个(而不是使用cURL,这消除了依赖):
或者你可以使用wget从linux cron开始,如下所示:
- `* * * * * wget -O - http://localhost/infinite_loop.PHP`
或者您可以使用bitsadmin运行.bat文件从Windows Scheduler启动,该文件包含以下内容:
- bitsadmin /create infiniteloop
- bitsadmin /addfile infiniteloop http://localhost/infinite_loop.PHP
- bitsadmin /resume infiniteloop