-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[discussion] libssh2 support #155
Labels
good first issue
Good for newcomers
Comments
或者提供个示例让人自己写个扩展支持swow协程的 |
随手搜到一个很厉害的repo:https://github.com/phpseclib/phpseclib <?php
require __DIR__ . '/../vendor/autoload.php';
use phpseclib3\Net\SSH2;
$host = 'your host';
$port = 22;
echo "Login to {$host}:{$port} and exec 'uname -a'...\n";
$ssh = new SSH2($host, $port);
echo 'Username: ';
$username = trim(fgets(STDIN));
echo 'Password: ';
system('stty cbreak -echo <&2');
$password = trim(fgets(STDIN));
system('stty cbreak echo <&2');
echo "\n";
$ssh->login($username, $password);
var_dump($ssh->exec('uname -a')); 你甚至可以通过 Swow 看到系统调用和数据流量日志来确认它是协程化的(用 swow-builder 编译时加上 --debug 参数,并在运行时设置环境变量 CAT_DEBUG=1): |
挺厉害的项目不过我目前的一个思路是改写ssh2扩展让他使用php stream函数这个应该好改 |
成功了把ssh2扩展底层连接函数以及libssh2收包跟发包回调都使用php stream就成功了 |
<?php
use Swow\Coroutine;
use Swow\Sync\WaitReference;
$wr1 = new WaitReference();
Coroutine::run(static function () use($wr1): void {
$wr = new WaitReference();
echo "start connect\r\n";
$session = ssh2_connect("x", 22);
echo "connect done!\r\n";
Coroutine::run(static function () use ($session, $wr): void {
echo "start auth\r\n";
$flag = ssh2_auth_password($session, 'x', 'x');
echo "auth done\r\n";
Coroutine::run(static function () use ($session,$wr): void {
// exec command
echo "Exec Command : sleep 5 && echo 'done 1!' \r\n";
ssh2_exec($session, "sleep 5 && echo 'done 1!'");
echo "Exec Command : sleep 5 && echo 'done 2!' \r\n";
ssh2_exec($session, "sleep 5 && echo 'done 2!'");
});
});
echo "auth 挂起\r\n";
WaitReference::wait($wr);
var_dump('done');
});
echo "connect 挂起\r\n";
WaitReference::wait($wr1);
echo "整体结束\r\n"; |
考虑下ffi?直接dlsym/GetProcAddress到libcat相关的函数地址喂给libssh2? |
突发奇想如果我跟上面的扩展一样统统使用php stream函数怎么样,等验证年后再说吧 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
是否可以添加libssh2支持我看libssh2文档是可以设置收包跟发包函数
The text was updated successfully, but these errors were encountered: