I have a PHP script which has a forever loop
<?php
while(1)
{
//Do something
}
?>
I need to run this script such that, even if I close my SSH session, it should always be running in the background. I know of cronjob, but cronjob will interrupt my script every 1 hour, for example. I want the script to be always running and not at specific times.
Can anyone tell me how to do this? (Its an Apache server running on Ubuntu)
Edit
Thanks to the commnets-
Now I have 3 options -
1) nohup php filename.php &
2) screen php filename.php
3) Doing something like this using cronjob http://reviewsignal.com/blog/2013/08/22/long-running-processes-in-php/
Can anyone tell me which is a better option? I want such that, even if an error occurs or it may be killed, or it may crash for some reason, the script should restart itself.