Reputation: 7444
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?
Upvotes: 18
Views: 24704
Reputation: 1594
Assuming you are working with a shared hosting server, and have no access to command line or ssh or hosting support team...
your best shot would be using your website management panel to trigger php restart.
this happens when you switch php version / change php ini params such as memory limit
Upvotes: 3
Reputation: 762
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.
Upvotes: 1
Reputation: 1645
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 ;-)
Upvotes: 2
Reputation: 1997
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.
Upvotes: 2
Reputation: 51797
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
Upvotes: 16