konstantin-kuklin/stream-library

流函数包装器

1.0.1 2018-04-07 05:58 UTC

This package is not auto-updated.

Last update: 2024-09-22 08:17:20 UTC


README

Build Status Scrutinizer Code Quality Scrutinizer Test Coverage Latest Stable Version Total Downloads

README

什么是StreamLibrary?

StreamLibrary 是通过流函数实现的 PHP 包装器。它允许在更舒适的环境中与流进行工作。

要求

StreamLibrary 仅支持 PHP 5 及以上版本。

安装

安装 StreamLibrary 的最佳方式是使用 composer

composer.phar require konstantin-kuklin/stream-library:dev-master

文档

工作的第一步是创建 Stream 对象

$stream = new \Stream\Stream($path, $protocol, $port, $driver);

path - 系统中文件的路径、网络中的 IP 地址或我们将要工作的主机名

protocol - 协议类型的字符串值,可以是 Connection::PROTOCOL_TCP、Connection::PROTOCOL_UDP、Connection::PROTOCOL_UNIX

port - 连接的端口号。如果协议是 Connection::PROTOCOL_UNIX,则不需要。默认值 = 0。

driver - 实现 StreamDriverInterface 的对象。如果你的连接需要更改传输数据,你需要使用此对象描述逻辑。默认值是 null(表示数据没有被更改)

从 Stream 获取数据

$stream = new \Stream\Stream($path, $protocol, $port, $driver);
$stream->setReceiveMethod(new StreamGetContentsMethod($maxLength, $offset));
$stream->getContents();

maxLength - 读取的最大字节数。默认值是 -1(读取所有剩余的缓冲区)

offset - 在读取之前跳转到指定的偏移量。默认值是 -1(不偏移读取)

向 Stream 发送数据

$stream = new \Stream\Stream($path, $protocol, $port, $driver);
$stream->sendContents($contents);

contents - 可以包含任何字符串数据