nohup/cron/screen - Running script in backgroud - better option?
<p>I have a PHP script which has a forever loop</p>

<pre><code>&lt;?php
    while(1)
        {
             //Do something 
        }
?&gt;
</code></pre>

<p>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.</p>

<p>Can anyone tell me how to do this? (Its an Apache server running on Ubuntu)</p>

<p><strong>Edit</strong></p>

<p>Thanks to the commnets-</p>

<p>Now I have 3 options -</p>

<p>1) <code>nohup php filename.php &amp;</code></p>

<p>2) <code>screen php filename.php</code></p>

<p>3) Doing something like this using cronjob <a href="http://reviewsignal.com/blog/2013/08/22/long-running-processes-in-php/" rel="nofollow noreferrer">http://reviewsignal.com/blog/2013/08/22/long-running-processes-in-php/</a></p>

<p>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.</p>