emersion/php-wrappers

该包已被放弃,不再维护。未建议替代包。

高性能的本地FTP和SFTP函数包装器。

dev-master 2020-02-13 14:47 UTC

This package is not auto-updated.

Last update: 2020-12-25 20:53:54 UTC


README

高性能的本地FTP和SFTP函数包装器。

使用方法

<?php
use Wrappers\FtpStream;

FtpStream::register(); // Replace the built-in wrapper

var_dump(file_put_contents('ftp://host/lol.txt', 'Hello world'));
var_dump(file_get_contents('ftp://host/lol.txt'));

var_dump(filesize('ftp://host/lol.txt'));

FtpStream::unregister(); // Restore the built-in wrapper
?>

为什么使用它?

默认的PHP ftp:// 包装器在用后立即关闭连接,这会导致进行多次请求时脚本运行变慢。此包装器替代方案可以保持连接(会话)打开,直到脚本终止,这样您就可以以更快的速度传输文件。

您可以使用几乎所有的原生PHP函数与此包装器一起使用。

也支持 ftps://sftp://,分别使用 FtpsStreamSftpStream(对于SFTP,您需要启用ssh2 扩展)。

性能

(数值越低越好)

您可以使用 tests/benchmark.php 运行基准测试。

方法

<?php
var_dump(FtpStream::is_registered()); // Returns true if the wrapper is already registered
FtpStream::register(); // Register the wrapper
FtpStream::unregister(); // Restore the default wrapper
FtpStream::close_all(); // Closes all connections before the end of the script