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?
In general, you should be able to run the script from the command-line like this
php myscript.php
Doing it on a remote host via ssh could be done like this
ssh [email protected] "php myscript.php"
try
php script.php.
If that doesn't work, you would have to locate the php executable and then execute it.
Btw, you can use screen, so if the connection to the computer is lost, the script still runs.
Alternatively you can just call ignore_user_abort()
and close your browser after you hit the page.
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
In addition to what everyone else said, you'll probably want to use nohup
as well.
ssh user@host "nohup php script.php"
That way it'll keep running even if your ssh connection drops. You could also use screen
in place of nohup
if you want.