10

I've used libraries like Fabric (Python) to perform various tasks on a remote server. When I run tasks via this library, I get the output from the remote server as the actions are happening. For example, if the task is executing a git pull on the server, I get the line by line output of that as it happens.

However, when I look at the various PHP SSH libs and the SSH2 extension. It appears there is only a way to get ALL of the output of from the command after it has already happened, in one long string. I would like to be fed output back from the remote server as the task is running. Is this possible? In pseudocode, this is kind of what I'm looking for:

Server::run('git pull origin master', function($output)
{
     echo $output.PHP_EOL;
});
4

2 回答 2

11

得到这个工作。您可以在循环中读取ssh2_exec使用返回的流。fgets

于 2013-05-06T01:28:54.577 回答
0

你可以flush()在每次回声后打电话

http://php.net/manual/en/function.flush.php

于 2013-05-06T01:19:31.550 回答