Php – How to run a php script through SSH?

phpssh

I have a rather long php script and whenever my internet connection skips out for a second the browser seems to stop the script. I can't sit around for 8 hours for my script to run so I figured I could just run it via ssh and be come back the next day and get my output file. However simple typing the scripts name into ssh doesn't seem to work. is there a special command to run php scripts through ssh?

Best Solution

If your internet connection is dropping out, then this is probably going to be a problem across SSH as well, and well, having an SSH window open isn't always the best thing to do (what happens if you accidentally close the ssh window?)

I would suggest SSHing into the server, then running a program called "screen", which will keep on running whatever you run inside of it, even if your connection drops.

To do this, first ssh into the server, and type

screen

This will load up screen, hit enter to bypass the welcome screen

Now, run your PHP script

php /path/to/your/php/script.php

this will start PHP running,

You can now close the window if you want, and the script will keep on running

To get back to your screen session, connect to the server, and run the command

screen -raAD

which will reconnect you to your session, as if you'd had the window open all the time.

This is actually pretty good for running long winded scripts, or even for running a console based IRC session :D