当前位置: 首页>>代码示例>>PHP>>正文


PHP stream_set_read_buffer函数代码示例

本文整理汇总了PHP中stream_set_read_buffer函数的典型用法代码示例。如果您正苦于以下问题:PHP stream_set_read_buffer函数的具体用法?PHP stream_set_read_buffer怎么用?PHP stream_set_read_buffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了stream_set_read_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;
     }
 }
开发者ID:koolkode,项目名称:async,代码行数:28,代码来源:SocketFactory.php

示例2: generate

 /**
  * Generates random bytes as a string of given length.
  *
  * <code>
  * echo Txp::get('\Textpattern\Password\Random')->generate(196);
  * </code>
  *
  * @param  int $length The length of the generated value
  * @return string The value
  */
 public function generate($length)
 {
     $bytes = (int) ceil($length / 2);
     if (function_exists('mcrypt_create_iv') && version_compare(PHP_VERSION, '5.3.0') >= 0) {
         $random = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
         if ($random && strlen($random) === $bytes) {
             return substr(bin2hex($random), 0, $length);
         }
     }
     if (IS_WIN === false && file_exists('/dev/urandom') && is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== false) {
         if (function_exists('stream_set_read_buffer')) {
             stream_set_read_buffer($fp, 0);
         }
         $random = fread($fp, $bytes);
         fclose($fp);
         if ($random && strlen($random) === $bytes) {
             return substr(bin2hex($random), 0, $length);
         }
     }
     if (IS_WIN === false && function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4') >= 0) {
         $random = openssl_random_pseudo_bytes($bytes, $strong);
         if ($random && $strong === true && strlen($random) === $bytes) {
             return substr(bin2hex($random), 0, $length);
         }
     }
     return parent::generate($length);
 }
开发者ID:ClaireBrione,项目名称:textpattern,代码行数:37,代码来源:Random.php

示例3: dmx_connect

function dmx_connect()
{
    global $debug, $dmx, $read_buffer;
    $r = trim(`ls -1 /dev/serial/by-id 2>/dev/null |grep "DMX"`);
    if ($r == '') {
        logformat("No USB DMX Interface appears to be connected!\n");
        exit(1);
    }
    $t = explode("-", $r);
    if (isset($t[1])) {
        logformat(sprintf("Found a %s\n", $t[1]));
    }
    $interface = "/dev/serial/by-id/" . $r;
    `stty -F {$interface} 230400 raw -echo`;
    if ($dmx = fopen($interface, 'w+')) {
        stream_set_blocking($dmx, 0);
        stream_set_read_buffer($dmx, 2048);
        $data = '';
        dmx_set_levels($data);
        dmx_set_dmx_receive_mode(SEND_ON_CHANGE_ONLY);
        sleep(1);
        while ($b = fread($dmx, 2048)) {
        }
        //empty the buffer
        $data = "Hello World!";
        dmx_set_parameters(27, 4, 40, $data);
        if (!($c = dmx_request_parameters($read_buffer))) {
            dmx_close();
            return 0;
        }
        return $c;
    }
    return 0;
}
开发者ID:JakDaniels,项目名称:hac_xap,代码行数:34,代码来源:dmxlib.inc.php

示例4: __construct

 public function __construct($stream, LoopInterface $loop)
 {
     $this->stream = $stream;
     if (!is_resource($this->stream) || get_resource_type($this->stream) !== "stream") {
         throw new InvalidArgumentException('First parameter must be a valid stream resource');
     }
     stream_set_blocking($this->stream, 0);
     // Use unbuffered read operations on the underlying stream resource.
     // Reading chunks from the stream may otherwise leave unread bytes in
     // PHP's stream buffers which some event loop implementations do not
     // trigger events on (edge triggered).
     // This does not affect the default event loop implementation (level
     // triggered), so we can ignore platforms not supporting this (HHVM).
     if (function_exists('stream_set_read_buffer')) {
         stream_set_read_buffer($this->stream, 0);
     }
     $this->loop = $loop;
     $this->buffer = new Buffer($this->stream, $this->loop);
     $that = $this;
     $this->buffer->on('error', function ($error) use($that) {
         $that->emit('error', array($error, $that));
         $that->close();
     });
     $this->buffer->on('drain', function () use($that) {
         $that->emit('drain', array($that));
     });
     $this->resume();
 }
开发者ID:EmmanuelMarti,项目名称:Koffee4Free,代码行数:28,代码来源:Stream.php

示例5: get_random_bytes

 function get_random_bytes($count)
 {
     $output = '';
     if (@is_readable('/dev/urandom') && ($fh = @fopen('/dev/urandom', 'rb'))) {
         if (function_exists('stream_set_read_buffer')) {
             stream_set_read_buffer($fh, 0);
         }
         $output = fread($fh, $count);
         fclose($fh);
     } elseif (function_exists('openssl_random_pseudo_bytes')) {
         $output = openssl_random_pseudo_bytes($count, $orpb_secure);
         if ($orpb_secure != true) {
             $output = '';
         }
     } elseif (defined('MCRYPT_DEV_URANDOM')) {
         $output = mcrypt_create_iv($count, MCRYPT_DEV_URANDOM);
     }
     if (strlen($output) < $count) {
         $output = '';
         for ($i = 0; $i < $count; $i += 16) {
             $this->random_state = md5(microtime() . $this->random_state);
             $output .= pack('H*', md5($this->random_state));
         }
         $output = substr($output, 0, $count);
     }
     return $output;
 }
开发者ID:nnguyen,项目名称:oscommerce2,代码行数:27,代码来源:passwordhash.php

示例6: generateRandomString

 /**
  * Generate a random string by using openssl, dev/urandom or random
  * @param int $length optional length of the string
  * @return string random string
  * @author Benjamin BALET <benjamin.balet@gmail.com>
  */
 private function generateRandomString($length = 10)
 {
     if (function_exists('openssl_random_pseudo_bytes')) {
         $rnd = openssl_random_pseudo_bytes($length, $strong);
         if ($strong === TRUE) {
             return base64_encode($rnd);
         }
     }
     $sha = '';
     $rnd = '';
     if (file_exists('/dev/urandom')) {
         $fp = fopen('/dev/urandom', 'rb');
         if ($fp) {
             if (function_exists('stream_set_read_buffer')) {
                 stream_set_read_buffer($fp, 0);
             }
             $sha = fread($fp, $length);
             fclose($fp);
         }
     }
     for ($i = 0; $i < $length; $i++) {
         $sha = hash('sha256', $sha . mt_rand());
         $char = mt_rand(0, 62);
         $rnd .= chr(hexdec($sha[$char] . $sha[$char + 1]));
     }
     return base64_encode($rnd);
 }
开发者ID:shawnyeh,项目名称:jorani,代码行数:33,代码来源:session.php

示例7: random_bytes

 /**
  * Use /dev/arandom or /dev/urandom for random numbers
  * 
  * @ref http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers
  * 
  * @param int $bytes
  * @return string
  */
 function random_bytes($bytes)
 {
     static $fp = null;
     if ($fp === null) {
         if (is_readable('/dev/arandom')) {
             $fp = fopen('/dev/arandom', 'rb');
         } else {
             $fp = fopen('/dev/urandom', 'rb');
         }
     }
     if ($fp !== false) {
         $streamset = stream_set_read_buffer($fp, 0);
         if ($streamset === 0) {
             $remaining = $bytes;
             do {
                 $read = fread($fp, $remaining);
                 if ($read === false) {
                     // We cannot safely read from urandom.
                     $buf = false;
                     break;
                 }
                 // Decrease the number of bytes returned from remaining
                 $remaining -= RandomCompat_strlen($read);
                 $buf .= $read;
             } while ($remaining > 0);
             if ($buf !== false) {
                 if (RandomCompat_strlen($buf) === $bytes) {
                     return $buf;
                 }
             }
         }
     }
     throw new Exception('PHP failed to generate random data.');
 }
开发者ID:skyosev,项目名称:random_compat,代码行数:42,代码来源:random.php

示例8: __construct

 /**
  * @param resource $resource
  * @param bool $autoClose
  * @throws InvalidArgumentException
  */
 public function __construct($resource, $autoClose = true)
 {
     parent::__construct($resource, $autoClose);
     $this->readable = true;
     $this->bufferSize = 4096;
     if (function_exists('stream_set_read_buffer')) {
         stream_set_read_buffer($this->resource, 0);
     }
 }
开发者ID:khelle,项目名称:surume,代码行数:14,代码来源:StreamReader.php

示例9: readFromStatus

 private function readFromStatus()
 {
     stream_set_blocking($this->pipeHandles[3], 0);
     stream_set_read_buffer($this->pipeHandles[3], 0);
     $status = '';
     while (!feof($this->pipeHandles[3])) {
         $status .= fread($this->pipeHandles[3], 1);
     }
     return $status;
 }
开发者ID:paul-schulleri,项目名称:phive,代码行数:10,代码来源:GnuPG.php

示例10: __construct

 /**
  * Wrapper around the stream.
  * Provides async and non async write access required for threads
  * @param ForkableLoopInterface $loop
  * @param resource $connection
  */
 public function __construct(ForkableLoopInterface $loop, $connection)
 {
     $this->loop = $loop;
     $this->connection = $connection;
     $this->buffer = new BinaryBuffer();
     $this->ThrowOnConnectionInvalid();
     if (function_exists('stream_set_read_buffer')) {
         stream_set_read_buffer($this->connection, 0);
     }
     $this->attachReadStream();
 }
开发者ID:RogerWaters,项目名称:react-thread-pool,代码行数:17,代码来源:ThreadConnection.php

示例11: __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_read_buffer')) {
         stream_set_read_buffer($this->resource, 0);
     }
     $this->loop = $loop;
     $this->listening = false;
     $this->paused = true;
     $this->resume();
 }
开发者ID:kraken-php,项目名称:framework,代码行数:17,代码来源:AsyncStreamReader.php

示例12: __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_read_buffer($resource, 0);
     stream_set_chunk_size($resource, self::CHUNK_SIZE);
     $this->queue = new \SplQueue();
     $this->poll = $this->createPoll($resource, $this->queue);
     $this->onCancelled = function () {
         $this->poll->cancel();
         $this->queue->shift();
     };
 }
开发者ID:icicleio,项目名称:stream,代码行数:16,代码来源:ReadablePipe.php

示例13: getPointer

 /**
  * Returns the pointer to the random source.
  * @return resource The pointer to the random source.
  */
 private function getPointer()
 {
     if (!isset($this->pointer)) {
         $this->pointer = fopen($this->source, 'r');
         // File read buffering is not supported on HHVM
         if (!defined('HHVM_VERSION')) {
             stream_set_chunk_size($this->pointer, 32);
             stream_set_read_buffer($this->pointer, 32);
         }
     }
     return $this->pointer;
 }
开发者ID:riimu,项目名称:kit-securerandom,代码行数:16,代码来源:RandomReader.php

示例14: 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";
     }
 }
开发者ID:bharathiselvan,项目名称:kafka,代码行数:18,代码来源:SimpleConsumer.php

示例15: 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;
 }
开发者ID:ivixlabs,项目名称:sync-daemon,代码行数:14,代码来源:SyncDaemonClient.php


注:本文中的stream_set_read_buffer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。