Stopping an infinite loop on a remote server PHP

那年仲夏 提交于 2019-12-03 19:47:56

问题


I have a simple infinite for loop looking like this:

set_time_limit (0);
for (;;)
{
    ... //Doing some stuff including to write to a file
    sleep(300);
}

It's running on my server. (Shared hosting account)

How on earth can I stop it?


回答1:


kill the process. assuming you can get access to the console via ssh and your server runs on linux:

ps -ef | grep php // to get a list of php-processes

kill [process-id] // kill the process by process-id



回答2:


You might want to contact your hosting service and ask them to kill your script. Most likely you don't have execute-access or ssh-access. Maybe you should build a possibility to quit your program next time you create an infinite loop.




回答3:


I logged in via SSH and tried killing the process but it didn't seem to work - possibly the incorrect process as there were quite a few there.

You can always restart apache as a last resort; that will fix it ;-)




回答4:


You mentioned writing to a file.

But if you were writing to a database you can use your database tool to temporarily rename a field which would trigger an error and stop your script.

The woes of shared servers, rapid dev and typos.



来源:https://stackoverflow.com/questions/7526701/stopping-an-infinite-loop-on-a-remote-server-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!