SSH Connection drops - but does my script keep running?

Hello there.

I'm fairly new to Linux, but I am connecting via SSH and PuTTY to a remote server, and I am running a fairly heavy MySQL script in a PHP page.

Our connection here is dodgy to say the least and I get continuous disconnections.

My question is, when I get disconnected, does my script carry on, or does it end after doing the query it was on when I get disconnected.

The problem I have, is that the first thing the PHP script does is run a big query that takes upto 10 minutes to complete, before looping through all the records.

The big query is the bit its on when I get disconnected, and I don't know whether the script is getting to the loop or not...

Thanks, Chris

Hi,
A disconnection usually sends a signal (HUP = hangup) to your script. Unless your script takes care of this signal (e.g. uses the trap command) it should stop after finishing the query.
The most common way to protect a script from receiving the HUP-signal is to start it using the nohup command:

nohup /path/to/script

Input and output are redirected when you use nohup.

1 Like

Thanks mate. I'm running it like that now, and we'll see what happens...

You can also use screen ,which permits a reconnection to the running process.

Thanks frans.

cero - your solution worked. Many thanks, you may have stopped me going home and boiling my own head.

I was trying to run

php Collection.php -d &

But it just wouldn't have it for some reason...