本文整理汇总了PHP中stream_set_write_buffer函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_set_write_buffer函数的具体用法?PHP stream_set_write_buffer怎么用?PHP stream_set_write_buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了stream_set_write_buffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: connectToAddress
protected function connectToAddress(string $address, float $timeout, bool $encrypt)
{
$url = \sprintf('%s://%s', $this->protocol, $address);
$errno = null;
$errstr = null;
$context = \stream_context_create(\array_replace_recursive($this->options, ['socket' => ['connect' => $address]]));
$socket = @\stream_socket_client($url, $errno, $errstr, $timeout ?: null, \STREAM_CLIENT_CONNECT | \STREAM_CLIENT_ASYNC_CONNECT, $context);
if (!\is_resource($socket)) {
throw new SocketException(\sprintf('Could not connect to "%s" (%s): [%s] %s', $url, $this->peer, $errno, \trim($errstr)));
}
try {
\stream_set_blocking($socket, false);
\stream_set_read_buffer($socket, 0);
\stream_set_write_buffer($socket, 0);
if ($this->tcpNoDelay) {
Socket::setTcpNoDelay($socket, true);
}
if ($encrypt) {
yield from $this->encryptSocketClient($socket, $timeout);
} else {
(yield new AwaitWrite($socket, $timeout));
}
return $socket;
} catch (\Throwable $e) {
Socket::shutdown($socket);
throw $e;
}
}
示例2: __construct
public function __construct($stream)
{
parent::__construct($stream);
stream_set_blocking($stream, 0);
stream_set_write_buffer($stream, 0);
$this->read = self::reader();
$this->write = self::writer();
}
示例3: __construct
/**
* Create a new pipe-based log handler.
*
* @param string $pipe Output pipe, defaults to STDERR.
*/
public function __construct($pipe = 'php://stderr', int $threshold = Logger::ALL, array $origins = [])
{
$pipe = \fopen($pipe, 'wb');
\stream_set_blocking($pipe, false);
\stream_set_write_buffer($pipe, 0);
$this->writer = new SocketWriter($pipe);
$this->threshold = $threshold;
$this->origins = $origins;
}
示例4: _connect
public function _connect()
{
$this->_socket = @pfsockopen($this->_host, $this->_port, $errno, $errstr, $this->_timeout);
if ($this->_socket === false) {
return new PHPTCP_Error($errno, $errstr);
}
stream_set_write_buffer($this->_socket, 0);
socket_set_timeout($this->_socket, $this->_timeout);
}
示例5: connect
/**
* Connect to Host
*
* @param string $host
* @param array $ssl
* @return AbstractClient
*/
protected function connect($host, array $ssl)
{
$this->socket = stream_socket_client($host, $errno, $errstr, ini_get('default_socket_timeout'), STREAM_CLIENT_CONNECT, stream_context_create(array('ssl' => $ssl)));
if (!$this->socket) {
throw new Exception\RuntimeException(sprintf('Unable to connect: %s: %d (%s)', $host, $errno, $errstr));
}
stream_set_blocking($this->socket, 0);
stream_set_write_buffer($this->socket, 0);
return $this;
}
示例6: __construct
/**
* @param resource $resource Stream resource.
* @param bool $autoClose True to close the resource on destruct, false to leave it open.
*/
public function __construct($resource, bool $autoClose = true)
{
parent::__construct($resource, $autoClose);
stream_set_write_buffer($resource, 0);
stream_set_chunk_size($resource, self::CHUNK_SIZE);
$this->writeQueue = new \SplQueue();
$this->onCancelled = function (Throwable $exception) {
$this->free($exception);
};
}
示例7: add
/**
* add a new request to the pool.
*/
public function add(Resource $r)
{
$stream = $r->stream;
$id = (int) $stream;
if (isset($this->streams[$id])) {
return $this->streams[$id];
}
stream_set_blocking($stream, 0);
stream_set_write_buffer($stream, 0);
return $this->streams[$id] = $r;
}
示例8: _connect
protected function _connect()
{
$sURL = $this->asurls[$this->_environment];
$streamContext = stream_context_create(array('ssl' => array('verify_peer' => isset($this->_rootCertificationAuthorityFile), 'cafile' => $this->_rootCertificationAuthorityFile, 'local_cert' => $this->_providerCertificateFile)));
$this->_hSocket = @stream_socket_client($sURL, $nError, $sError, $this->_connectTimeout, STREAM_CLIENT_CONNECT, $streamContext);
if (!$this->_hSocket) {
throw new Exception("Unable to connect to '{$sURL}': {$sError} ({$nError})");
}
stream_set_blocking($this->_hSocket, 0);
stream_set_write_buffer($this->_hSocket, 0);
return true;
}
示例9: __construct
/**
* @param resource $resource
* @param LoopInterface $loop
* @param bool $autoClose
* @throws InvalidArgumentException
*/
public function __construct($resource, LoopInterface $loop, $autoClose = true)
{
parent::__construct($resource, $autoClose);
if (function_exists('stream_set_write_buffer')) {
stream_set_write_buffer($this->resource, 0);
}
$this->loop = $loop;
$this->listening = false;
$this->paused = true;
$this->buffer = new Buffer();
$this->resume();
}
示例10: record
public function record($level, $logStr)
{
$timeStr = '[' . date('Y-m-d H:i:s O') . ']';
$fp = fopen($this->_filename, 'ab');
if (false !== $fp) {
stream_set_write_buffer($fp, $this->_write_buff);
fwrite($fp, $timeStr . ' ' . $logStr . PHP_EOL);
fclose($fp);
} else {
return false;
}
return true;
}
示例11: connect
/**
* Connect to Kafka via socket
*
* @return void
*/
public function connect()
{
if (!is_resource($this->conn)) {
$this->conn = stream_socket_client('tcp://' . $this->host . ':' . $this->port, $errno, $errstr);
if (!$this->conn) {
throw new RuntimeException($errstr, $errno);
}
stream_set_timeout($this->conn, $this->socketTimeout);
stream_set_read_buffer($this->conn, $this->socketBufferSize);
stream_set_write_buffer($this->conn, $this->socketBufferSize);
//echo "\nConnected to ".$this->host.":".$this->port."\n";
}
}
示例12: stream_set_option
public function stream_set_option($option, $arg1, $arg2)
{
switch ($option) {
case STREAM_OPTION_BLOCKING:
stream_set_blocking($this->fileSource, $arg1);
break;
case STREAM_OPTION_READ_TIMEOUT:
stream_set_timeout($this->fileSource, $arg1, $arg2);
break;
case STREAM_OPTION_WRITE_BUFFER:
stream_set_write_buffer($this->fileSource, $arg1, $arg2);
}
}
示例13: run
public function run()
{
if (!($ipcSocket = @stream_socket_client($this->ipcUri, $errno, $errstr, 5))) {
throw new \RuntimeException(sprintf("Failed connecting to IPC server: (%d) %s", $errno, $errstr));
}
stream_set_write_buffer($ipcSocket, 0);
stream_socket_shutdown($ipcSocket, STREAM_SHUT_RD);
$openMsg = $this->getThreadId() . "\n";
if (@fwrite($ipcSocket, $openMsg) !== strlen($openMsg)) {
throw new \RuntimeException("Failed writing open message to IPC server");
}
$this->ipcSocket = $ipcSocket;
}
示例14: init
private function init()
{
$connection = @stream_socket_client('tcp://' . $this->host . ':' . $this->port);
stream_set_write_buffer($connection, 0);
stream_set_read_buffer($connection, 0);
if (!$connection) {
throw new \Exception('No SyncDaemon available.');
}
$data = trim(fgets($connection));
if ($data != self::ACCEPT) {
throw new \Exception('Connection faild. Wrong answer: ' . $data);
}
$this->connection = $connection;
}
示例15: connect
/**
* {@inheritdoc}
*/
public function connect()
{
if ($this->sock) {
return;
}
$this->sock = stream_socket_client($this->uri, $errno, $errstr, $this->timeout);
if (!$this->sock) {
throw new \RuntimeException("Can't connect to the server at '{$this->uri}' ({$errno}: {$errstr})");
}
stream_set_timeout($this->sock, $this->timeout);
stream_set_blocking($this->sock, $this->blocking);
stream_set_read_buffer($this->sock, 0);
// 64k
stream_set_write_buffer($this->sock, 0);
}