Will running nohup without & make the script stop when connection to remote server is lost?

517 views Asked by At

I am running a script nohup php /var/www/html/foo.php an immediately i hit enter,it gives me nohup: ignoring input and appending output tonohup.out'`

My script is processing mysql records using pdo

$dbh = new PDO('mysql:host=localhost;dbname=odesk', 'root', '');
$sth = $dbh->prepare("SELECT id,msisdn from new_tableu limit 91471,10");
$sth->execute();

while($result = $sth->fetch(PDO::FETCH_ASSOC)){
}

Does this mean once i internet disconnects,my script too will stop?.

I could run my script in the background with nohup php /var/www/html/foo.php & but its running forever which is not what i want.

1

There are 1 answers

0
Antoan Milkov On BEST ANSWER

It is save to run it as:

nohup php /var/www/html/foo.php

There will be no interruptions when you are disconnected.

My advice is to try screen, since this way you can disconnect then reconnect and check the script output

screen php /var/www/html/foo.php

This way I was running bunch of scripts that take few weeks to finish and each day I checked the progress.