문제

I want to use functionality like here. Please check the code bellow

function notify (
    $notification_code,
    $severity,
    $message,
    $message_code,
    $bytes_transferred,
    $bytes_max
) {
    echo "Runned \n";
};

$ctx = stream_context_create();
stream_set_params($ctx, array('notification' => 'notify'));
$ssh_connection = ssh2_connect('myhost');
ssh2_auth_password($ssh_connection, 'login','pass');
$sftp_resource = ssh2_sftp($ssh_connection);
$data = file_get_contents("ssh2.sftp://{$sftp_resource}/path/to/big/file",
            false, $ctx);

I expect that my notify function will be called at least once. Actually, the same code works for ftp wrappers

function notify (
    $notification_code,
    $severity,
    $message,
    $message_code, 
    $bytes_transferred,
    $bytes_max
) {
    echo "Runned \n";
};

$ctx = stream_context_create();
stream_set_params($ctx, array('notification' => 'notify'));
$scheme = 'ftp';
$data = file_get_contents("{scheme}://username:password@host:port/path/to/file",
            false, $ctx);

And it works fine! The notify function is called many times. I try to use sftp wrapper like this

$data = file_get_contents("ssh2.sftp://username:password@host:port/path/to/big/file",
            false, $ctx);

And it isn`t works too. Any ideas?

도움이 되었습니까?

해결책

The ssh2 extension doesn't support notfication callbacks. I don't know if this is by design or just not implemented, but the extensions code is missing calls to functions like:

From (PHP-5.4.10) /ext/standard/ftp_fopen_wrapper.c, line 573:

php_stream_notify_progress_init(context, 0, file_size);

A workaround, which I've not tested yet might be to use ftps:// (FTP over ssl). It should fit your security needs and - as the code looks like - will support notifications as ftp. In detail, it uses the same urlwrapper as ftp.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top