How to set timeout for a ssh command executed with php?
php, timeout
Solution
Wrap your command with the UNIX `timeout` utility.
system('timeout n ../my/aa');
^
Where `n` is some integer value in seconds.
If the command times out, then exit with status 124. Otherwise, exit with the status of COMMAND. If no signal is specified, send the TERM signal upon timeout. The TERM signal kills any process that does not block or catch that signal. For other processes, it may be necessary to use the KILL (9) signal, since this signal cannot be caught.
Problem
I use php to execute scp commands via ssh via a wrapper function. The moves are between local and remote servers. I roughly know how long the script should execute for, and I would like to kill the scp process if its taking too long (due to a destination server getting bogged down, or other network issues). When this happens currently, the scp processes get locked up completely until the destination server is restarted or the scp processes are killed manually from command line. Can I pass some kind of timeout into shell_exec() that will quit the work its doing and proceed with the script execution?