用PHP在远程服务器上执行命令--不需要回调流。

问题描述 投票:2回答:2

我一直在寻找 这里 试图弄清楚这个问题,但我不完全理解所有的参数,所以我将解释一下我想做的事情。

我想在远程Linux(Ubuntu)服务器上通过PHP使用现有的变量$myfile(表示类似'music.mp3')运行下面的命令。

wget http://someaddress.com/$myfile /usr/incoming/$myfile lame --decode /usr/incoming/$myfile - | stereo_tool_cmd - - -s /usr/settings/process.sts | lame -b 128 - /usr/processed/$myfile

这样做的目的是告诉远程服务器下载一个文件(http:/someaddress.com$myfile)然后用lame解码成wav,然后用立体声工具处理,再重新编码成128k的mp3,并将其移动到指定目录。

我不需要发端服务器收到任何形式的处理反馈,它只需要在远程服务器上启动它。我如何在PHP中进行设置?

下面是我在上面链接的 PHP.net 页面,可能是我需要使用的,但我不知道如何设置。

 <?php
 $connection = ssh2_connect('shell.example.com', 22);
 ssh2_auth_password($connection, 'username', 'password');

 $stream = ssh2_exec($connection, '/usr/local/bin/php -i');
 ?>
php linux remote-access remote-server ssh2-exec
2个回答
1
投票

用.NET Framework 2.0来做什么?

 <?php
 $connection = ssh2_connect('shell.example.com', 22);
 ssh2_auth_password($connection, 'username', 'password');

 $stream = ssh2_exec($connection,'wget http://someaddress.com/'.$myfile.
    ' /usr/incoming/'.$myfile.' lame --decode /usr/incoming/'.$myfile.
    ' - | stereo_tool_cmd - - -s /usr/settings/process.sts | lame -b 128 - /usr/processed/'.$myfile);
?>

这应该工作得很好。

编辑1 最好把你的php变量放在字符串之外。

© www.soinside.com 2019 - 2024. All rights reserved.