PHPSecLib:在远程服务器上执行scp到另一台远程服务器会提前终止吗?

I'm attempting to copy a file between two remote servers via PHP using PHPSecLib.

SSH Keys exist between domain.tld and domain2.tld, and locally performing this SCP from domain.tld works fine.

Trimmed down version of my code:

echo "Copying file... ";
$ssh = new Net_SSH2('domain.tld');
$ssh->enableQuietMode();
$ssh->login('user','pass');

$ssh->exec("scp /home/file.tar.gz root@domain2.tld:/home/file.tar.gz");
if($ssh->getExitStatus())
    exit("Failed at line: ".__LINE__);

echo "Done!
";

In the example above, the script would finish after 5 seconds, echoing "Done!" at the end, however the copy has not completed and is still running for approx another 2 minutes.

Unfortuantely, I wish to remotely do things with the file that is being copied in this manner, thus waiting for it to complete is necessary.

I've investigated using PHPSecLib Net_SCP as well, unfortunately this cannot perform a remote -> remote copy, and I need to avoid using the local server as an intermediary for the copy process (Due to distance/bandwidth constraints).

I've attempted to re-write the above using $ssh->read() and $ssh->write(), however with limited understanding of how these procedures are supposed to work, I had no success.

Is anybody able to shine some light on this issue for me?

Are you using public key auth? If you're using password auth then you'd need an interactive prompt. Or you could use the sourcefile attribute too.

I tried it just now using public key auth and it worked just fine.

Answered the problem myself. It turns out that Net_SSH2 will automatically timeout an exec if no STDOUT is received within a default value. The answer was to call $ssh->setTimeout(60000) (or some other equally ridiculous number) before the exec statement.