在处理 PHP ssh2 函数时,我被困在某些地方。我有一个 demo.php 文件,我的代码如下所示:
$name = "myserver.com";
function get_host_list($name)
{
$connection = ssh2_connect($name,22);
ssh2_auth_password($connection, 'root','changeme');
$sftp = ssh2_sftp($connection);
$stream = ssh2_exec($connection, 'python file.py');
stream_set_blocking($stream, true);
// Return the result and delete the files
$host_list = stream_get_contents($stream);
return $host_list;
}
echo get_host_list($name);
当我在 shell 中运行文件时,一切正常:
php demo.php
正确的结果显示在屏幕上。但是当我尝试在浏览器上打开 php 文件时,什么都没有显示。
www.path/to/the/file.demo.php
该页面可以打开,但没有返回任何内容。
我猜问题是页面加载后,php文件还没有得到结果,所以什么都显示不了。
请帮帮我,不知道如何解决。:(