我正在使用 L 5.8 并且我有一個包含 3 個輸入的表單

現在,我可以使用此包通過 SSH 連接到特定服務器laravelcollective/remote": "~5.8。我需要預先 配置IP、UN、PW 之config/remote.php類的:
'connections' => [
'production' => [
'host' => '1.1.1.1',
'username' => 'code',
'password' => '8888',
'key' => '',
'keytext' => '',
'keyphrase' => '',
'agent' => '',
'timeout' => 10,
],
],
然后,我可以輕松運行任何命令甚至鏈接它們
$commands = ['cd /home/code && ./runMe.sh'];
SSH::run($commands, function($line)
{
echo $line.PHP_EOL;
});
結果
我的門戶將連接到該服務器并成功運行該命令,并且我已經對其進行了驗證。
現在
我需要從表單輸入中讀取它。是否可以使用相同的插件并動態設定該檔案remote.php?
或者
我應該開始研究別的東西,因為這是一個死胡同嗎?
請指教,
uj5u.com熱心網友回復:
您可以在config()此處使用幫助程式:
示例配置:
config([
'remote.connections.production.host' => $request->input('hostname'),
'remote.connections.production.username' => $request->input('username'),
'remote.connections.production.password' => $request->input('password')
]);
然后呼叫:
$commands = ['cd /home/code && ./runMe.sh'];
SSH::run($commands, function($line)
{
echo $line.PHP_EOL;
});
uj5u.com熱心網友回復:
此示例需要包php-ssh2,并提供多種方法來檢索遠程 shell STDOUT 作為流。控制當前機器外殼并獲得回應也很棒。
sudo apt install php-ssh2
或按版本:
sudo apt install php7.4-ssh2
的實施例的使用ssh2_exec()和ssh2_fetch_stream():
<?php
$ssh = ssh2_connect('192.162.68.212', 22); // Remote address
ssh2_auth_password($ssh, 'root', 'XQA8DCamdEm'); // Credentials
$shell = ssh2_shell($ssh, 'xterm'); // Choose remote shell
$stream = ssh2_exec($ssh, 'cd /home/code && ./runMe.sh'); // Remote command
stream_set_blocking($stream, true); // Wait for multiline output, till EOF
$stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO); // SSH2_STREAM_STDERR
echo stream_get_contents($stream_out); // Print in real-time
可以只檢索錯誤,這非常適合僅通過使用 flag 進行監視而不決議整個輸出SSH2_STREAM_STDERR。
要寫入字串只能STDERR從遠程PHP,我們可以使用:
fwrite(STDERR, "Some logs, from machine (...)\n");
或者我們可以直接在遠程 shell 命令中管道錯誤:
cd /home/code && ./runMe.sh 2>
https://www.php.net/manual/en/ref.ssh2.php
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/350323.html
標籤:php 拉拉维尔 laravel-5 ssh laravel-5.8
上一篇:快速將200多個資料插入具有關系的表-Laravel5.6
下一篇:如何從我自己的System命名空間(包含我的自定義Int32)中訪問dotnet的System.Int32型別?
