On a LAMP box, I am calling the SCP copy function via PHP's exec function in a loop to copy several images to a remote server:
exec("scp ".$this->GetUploadPath(true)." ".$currentServer->Scp.":".$this->GetServerPath($currentServer, true));
Result: Works fine, but the PHP script takes several seconds to finish.
However I do not want the PHP script to wait for the SCP job to finish so I tried one the following:
exec("nohup scp ".$this->GetUploadPath(true)." ".$currentServer->Scp.":".$this->GetServerPath($currentServer, true) . " 1>/dev/null/ 2>&1 &");
Result: PHP script is much faster, however SCP is not finished. Images are not copied to the remote sever.
exec("nohup scp ".$this->GetUploadPath(true)." ".$currentServer->Scp.":".$this->GetServerPath($currentServer, true) . " &");
Result: Images are copied, however no improvement in php script running time, so I guess the php script still waits for the SCP routine to finish although I "backgrounded" the call.
Any ideas how to implement it, that the PHP script does not wait, but the SCP process is finished?
Thank you in advance!
Exceeding the maximum simultaneous connection to the server could be the problem. So limit the simultaneous connections or simply upload it one by one. If waiting before the browser is your problem, you could add the following to your php script
ignore_user_abort(true);
set_time_limit(0);
and upload using looping the following
exec("scp ".$this->GetUploadPath(true)." ".$currentServer->Scp.":".$this->GetServerPath($currentServer, true) . " 1>/dev/null/ 2>&1");
after triggering the php script from your browser, you could even close browser, the above piece of code will do the magic for you.