ssh2_tunnel 會回傳一個 socket 資料流(例如 fsockopen 的輸出)。您可以使用以下基本程式碼來傳送換行符號並取得任何輸出以測試其是否正常運作
fwrite($tunnel, "\n");
while (!feof($tunnel)) {
echo fgets($tunnel, 128);
}
提醒一下:您目前無法將此 socket 與任何 cURL 函式一起使用。
(PECL ssh2 >= 0.9.0)
ssh2_tunnel — 透過遠端伺服器開啟通道
範例 #1 開啟到任意主機的通道
<?php
$connection = ssh2_connect('shell.example.com', 22);
ssh2_auth_pubkey_file($connection, 'username', 'id_dsa.pub', 'id_dsa');
$tunnel = ssh2_tunnel($connection, '10.0.0.101', 12345);
?>