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


PHP stream_set_blocking函数代码示例

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


在下文中一共展示了stream_set_blocking函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sshiconn

function sshiconn($cmd, $pass, $ip, $sshp = 22)
{
    $ip = $_REQUEST['ip'];
    $pass = $_REQUEST['pass'];
    $sshp = $_REQUEST['sshp'];
    if (!isset($_REQUEST['sshp'])) {
        $sshp = '22';
    }
    $connection = ssh2_connect($ip, $sshp);
    if (!$connection) {
        throw new Exception("fail: unable to establish connection\nPlease IP or if server is on and connected");
    }
    $pass_success = ssh2_auth_password($connection, 'root', $pass);
    if (!$pass_success) {
        throw new Exception("fail: unable to establish connection\nPlease Check your password");
    }
    $stream = ssh2_exec($connection, $cmd);
    $errorStream = ssh2_fetch_stream($stream, SSH2_STREAM_STDERR);
    stream_set_blocking($errorStream, true);
    stream_set_blocking($stream, true);
    print_r($cmd);
    $output = stream_get_contents($stream);
    fclose($stream);
    fclose($errorStream);
    ssh2_exec($connection, 'exit');
    unset($connection);
    return $output;
}
开发者ID:shadowhome,项目名称:synxb,代码行数:28,代码来源:functions.php

示例2: connect

 /**
  * Connects the TCP socket to the host with the given IP address and port
  * number
  *
  * Depending on whether PHP's sockets extension is loaded, this uses either
  * <var>socket_create</var>/<var>socket_connect</var> or
  * <var>fsockopen</var>.
  *
  * @param string $ipAddress The IP address to connect to
  * @param int $portNumber The TCP port to connect to
  * @param int $timeout The timeout in milliseconds
  * @throws SocketException if an error occurs during connecting the socket
  */
 public function connect($ipAddress, $portNumber, $timeout)
 {
     $this->ipAddress = $ipAddress;
     $this->portNumber = $portNumber;
     if ($this->socketsEnabled) {
         if (!($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP))) {
             throw new SocketException(socket_last_error($this->socket));
         }
         socket_set_nonblock($this->socket);
         @socket_connect($this->socket, $ipAddress, $portNumber);
         $write = array($this->socket);
         $read = $except = array();
         $sec = floor($timeout / 1000);
         $usec = $timeout % 1000;
         if (!socket_select($read, $write, $except, $sec, $usec)) {
             $errorCode = socket_last_error($this->socket);
         } else {
             $errorCode = socket_get_option($this->socket, SOL_SOCKET, SO_ERROR);
         }
         if ($errorCode) {
             throw new SocketException($errorCode);
         }
         socket_set_block($this->socket);
     } else {
         if (!($this->socket = @fsockopen("tcp://{$ipAddress}", $portNumber, $socketErrno, $socketErrstr, $timeout / 1000))) {
             throw new SocketException($socketErrstr);
         }
         stream_set_blocking($this->socket, true);
     }
 }
开发者ID:heartless-gaming,项目名称:game-server-status,代码行数:43,代码来源:TCPSocket.php

示例3: load_data

/**
 * Send request to VIES site and retrieve results
 *
 * @access  public
 * @param   string
 * @return  mixed
 */
function load_data($url)
{
    $url = parse_url($url);
    if (!in_array($url['scheme'], array('', 'http'))) {
        return false;
    }
    $fp = fsockopen($url['host'], $url['port'] > 0 ? $url['port'] : 80, $errno, $errstr, 2);
    if (!$fp) {
        return false;
    } else {
        fputs($fp, "GET " . $url['path'] . (isset($url['query']) ? '?' . $url['query'] : '') . " HTTP/1.0\r\n");
        fputs($fp, "Host: " . $url['host'] . "\r\n");
        fputs($fp, "Connection: close\r\n\r\n");
        $data = '';
        stream_set_blocking($fp, false);
        stream_set_timeout($fp, 4);
        $status = socket_get_status($fp);
        while (!feof($fp) && !$status['timed_out']) {
            $data .= fgets($fp, 1000);
            $status = socket_get_status($fp);
        }
        if ($status['timed_out']) {
            return false;
        }
        fclose($fp);
        return $data;
    }
}
开发者ID:BackupTheBerlios,项目名称:oos-svn,代码行数:35,代码来源:function_validate_vatid.php

示例4: read

 /**
  * Read everything from standard input
  *
  * @param callable $lineCallback An operation to perform on each line read
  * @param callable $doneCallback An operation to perform when the end has been reached
  * @throws \RuntimeException if a timeout occurs
  * @link http://www.gregfreeman.org/2013/processing-data-with-php-using-stdin-and-piping/
  *       Based on "Processing data with PHP using STDIN and Piping" by Greg Freeman
  */
 public function read(callable $lineCallback, callable $doneCallback = null)
 {
     stream_set_blocking(STDIN, 0);
     $timeoutStarted = false;
     $timeout = null;
     while (1) {
         // I'm getting something...
         while (false !== ($line = fgets(STDIN))) {
             $lineCallback($line);
             if ($timeoutStarted) {
                 $timeoutStarted = false;
                 $timeout = null;
             }
         }
         // End of input
         if (feof(STDIN)) {
             if ($doneCallback) {
                 $doneCallback();
             }
             break;
         }
         // Wait a spell
         if (null === $timeout) {
             $timeout = time();
             $timeoutStarted = true;
             continue;
         }
         // Timeout
         if (time() > $timeout + $this->wait) {
             throw new \RuntimeException('Timeout reached while reading STDIN');
             return;
         }
     }
 }
开发者ID:shootproof,项目名称:shootproof-cli,代码行数:43,代码来源:StdinReader.php

示例5: setBlocking

 /**
  * @param bool $blocking
  */
 public function setBlocking($blocking)
 {
     $this->blocking = (bool) $blocking;
     foreach ($this->pipes as $pipe) {
         stream_set_blocking($pipe, $this->blocking);
     }
 }
开发者ID:christiaan,项目名称:stream-process,代码行数:10,代码来源:StreamProcess.php

示例6: SendMsg2Daemon

function SendMsg2Daemon($ip, $port, $msg, $timeout = 15)
{
    if (!$ip || !$port || !$msg) {
        return array(false);
    }
    $errno;
    $errstr;
    $fp = @fsockopen($ip, $port, $errno, $errstr, $timeout);
    if (!$fp) {
        return array(false);
    }
    stream_set_blocking($fp, true);
    stream_set_timeout($fp, $timeout);
    @fwrite($fp, $msg . "\n");
    $status = stream_get_meta_data($fp);
    $ret;
    if (!$status['timed_out']) {
        $datas = 'data:';
        while (!feof($fp)) {
            $data = fread($fp, 4096);
            if ($data) {
                $datas = $datas . $data;
            }
        }
        return array(true, $datas);
    } else {
        $ret = array(false);
    }
    @fclose($fp);
    return ret;
}
开发者ID:ifzz,项目名称:distri.lua,代码行数:31,代码来源:control_action.php

示例7: asteriskClient

/**
 * this function defines the asterisk client
 */
function asteriskClient()
{
    global $app_strings, $current_user;
    global $adb, $log;
    $data = getAsteriskInfo($adb);
    $server = $data['server'];
    $port = $data['port'];
    $username = $data['username'];
    $password = $data['password'];
    $version = $data['version'];
    $errno = $errstr = NULL;
    $sock = @fsockopen($server, $port, $errno, $errstr, 1);
    stream_set_blocking($sock, false);
    if ($sock === false) {
        echo "Socket cannot be created due to error: {$errno}:  {$errstr}\n";
        $log->debug("Socket cannot be created due to error:   {$errno}:  {$errstr}\n");
        exit(0);
    } else {
        echo "Date: " . date("d-m-Y") . "\n";
        echo "Connecting to asterisk server.....\n";
        $log->debug("Connecting to asterisk server.....\n");
    }
    echo "Connected successfully\n\n\n";
    $asterisk = new Asterisk($sock, $server, $port);
    authorizeUser($username, $password, $asterisk);
    //keep looping continuosly to check if there are any calls
    while (true) {
        //check for incoming calls and insert in the database
        sleep(2);
        $incoming = handleIncomingCalls($asterisk, $adb, $version);
    }
    fclose($sock);
    unset($sock);
}
开发者ID:vtiger-jp,项目名称:vtigercrm-5.1.x-ja,代码行数:37,代码来源:AsteriskClient.php

示例8: execute

 public function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln('Starting server on port 5000');
     $descriptorspec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
     $port = $input->getOption('port');
     // Start server process
     $process = proc_open("php -S localhost:{$port} -t public/ " . getcwd() . "/scripts/normal-server/router.php", $descriptorspec, $pipes, getcwd(), $_ENV);
     if (!is_resource($process)) {
         throw new Exception("popen error");
     }
     stream_set_blocking($pipes[0], 0);
     stream_set_blocking($pipes[1], 0);
     stream_set_blocking($pipes[2], 0);
     // Redirect all output
     while (!feof($pipes[1])) {
         foreach ($pipes as $pipe) {
             $line = fread($pipe, 128);
             if ($line) {
                 $output->writeln($line);
             }
         }
         sleep(0.5);
     }
     foreach ($pipes as $pipe) {
         fclose($pipe);
     }
 }
开发者ID:kiasaki,项目名称:vexillum,代码行数:27,代码来源:StartCommand.php

示例9: acceptSocket

 protected function acceptSocket()
 {
     $connection = stream_socket_accept($this->socket, 0);
     stream_set_blocking($this->socket, 0);
     self::log('Socket', 'accepted');
     return $connection;
 }
开发者ID:LookForwardPersistence,项目名称:appserver-in-php,代码行数:7,代码来源:LibEventUnbuffered.php

示例10: exec

 /**
  * @param $command
  * @param bool $display
  * @return array
  * @throws \Exception
  */
 public function exec($command, $display = true)
 {
     $outStream = ssh2_exec($this->stream, $command);
     $errStream = ssh2_fetch_stream($outStream, SSH2_STREAM_STDERR);
     stream_set_blocking($outStream, true);
     stream_set_blocking($errStream, true);
     $err = $this->removeEmptyLines(explode("\n", stream_get_contents($errStream)));
     if (count($err)) {
         if (strpos($err[0], 'Cloning into') === false) {
             // throw new \Exception(implode("\n", $err));
         }
     }
     $out = $this->removeEmptyLines(explode("\n", stream_get_contents($outStream)));
     fclose($outStream);
     fclose($errStream);
     if ($display) {
         if (!$this->output instanceof OutputInterface) {
             throw new \LogicException('You should set output first');
         }
         foreach ($out as $line) {
             $this->output->writeln(sprintf('<info>%s</info>', $line));
         }
     }
     return $out;
 }
开发者ID:seferov,项目名称:deployer-bundle,代码行数:31,代码来源:SshClient.php

示例11: _sock

 function _sock($url)
 {
     $host = parse_url($url, PHP_URL_HOST);
     $port = parse_url($url, PHP_URL_PORT);
     $port = $port ? $port : 80;
     $scheme = parse_url($url, PHP_URL_SCHEME);
     $path = parse_url($url, PHP_URL_PATH);
     $query = parse_url($url, PHP_URL_QUERY);
     if ($query) {
         $path .= '?' . $query;
     }
     if ($scheme == 'https') {
         $host = 'ssl://' . $host;
     }
     if ($fp = @fsockopen($host, $port, $error_code, $error_msg, 5)) {
         stream_set_blocking($fp, 0);
         //开启了手册上说的非阻塞模式
         $header = "GET {$path} HTTP/1.1\r\n";
         $header .= "Host: {$host}\r\n";
         $header .= "Connection: Close\r\n\r\n";
         //长连接关闭
         fwrite($fp, $header);
         fclose($fp);
     }
     return array($error_code, $error_msg);
 }
开发者ID:shitfSign,项目名称:php-cron,代码行数:26,代码来源:Cron.DB.Class.php

示例12: connect

 /**
  *
  * @param  string            $host Host to connect to. Default is localhost (127.0.0.1).
  * @param  int               $port Port to connect to. Default is 8080.
  * @return boolean           True on success
  * @throws \RuntimeException
  */
 protected function connect($host, $port)
 {
     $key1 = $this->generateRandomString(32);
     $key2 = $this->generateRandomString(32);
     $key3 = $this->generateRandomString(8, false, true);
     $header = "GET /echo HTTP/1.1\r\n";
     $header .= "Upgrade: WebSocket\r\n";
     $header .= "Connection: Upgrade\r\n";
     $header .= "Host: " . $host . ":" . $port . "\r\n";
     $header .= "Sec-WebSocket-Key1: " . $key1 . "\r\n";
     $header .= "Sec-WebSocket-Key2: " . $key2 . "\r\n";
     $header .= "\r\n";
     $header .= $key3;
     $this->socket = @stream_socket_client('tcp://' . $host . ':' . $port, $errno, $errstr, self::SOCKET_TIMEOUT);
     if (!$this->socket) {
         throw new \RuntimeException(sprintf('WebSocket connection error (%u): %s', $errno, $errstr));
     }
     stream_set_blocking($this->socket, false);
     // do a handshake
     if (!fwrite($this->socket, $header)) {
         throw new \RuntimeException('WebSocket write error');
     }
     /**
      * @todo: check response here. Currently not implemented cause "2 key handshake" is already deprecated.
      * See: http://en.wikipedia.org/wiki/WebSocket#WebSocket_Protocol_Handshake
      */
     // $response = fread($this->socket, 2000);
     return true;
 }
开发者ID:northdakota,项目名称:platform,代码行数:36,代码来源:WebSocket.php

示例13: __construct

 function __construct($config)
 {
     if (extension_loaded("pcntl")) {
         //Add signal handlers to shut down the bot correctly if its getting killed
         pcntl_signal(SIGTERM, array($this, "signalHandler"));
         pcntl_signal(SIGINT, array($this, "signalHandler"));
     } else {
         //die("Please make sure the pcntl PHP extension is enabled.\n");
     }
     $this->config = $config;
     $this->startTime = time();
     $this->lastServerMessage = $this->startTime;
     ini_set("memory_limit", $this->config['memoryLimit'] . "M");
     if ($config['verifySSL']) {
         $this->socket = stream_socket_client("" . $config['server'] . ":" . $config['port']) or die("Connection error!");
     } else {
         $socketContext = stream_context_create(array("ssl" => array("verify_peer" => false, "verify_peer_name" => false)));
         $this->socket = stream_socket_client("" . $config['server'] . ":" . $config['port'], $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $socketContext) or die("Connection error!");
     }
     stream_set_blocking($this->socket, 0);
     stream_set_timeout($this->socket, 600);
     $this->login();
     $this->loadPlugins();
     $this->main($config);
 }
开发者ID:sergejey,项目名称:majordomo-app_ircbot,代码行数:25,代码来源:VikingBot.php

示例14: connect

 public function connect()
 {
     $nick = $this->getConfig('nick', 'phabot');
     $server = $this->getConfig('server');
     $port = $this->getConfig('port', 6667);
     $pass = $this->getConfig('pass');
     $ssl = $this->getConfig('ssl', false);
     $user = $this->getConfig('user', $nick);
     if (!preg_match('/^[A-Za-z0-9_`[{}^|\\]\\-]+$/', $nick)) {
         throw new Exception(pht("Nickname '%s' is invalid!", $nick));
     }
     $errno = null;
     $error = null;
     if (!$ssl) {
         $socket = fsockopen($server, $port, $errno, $error);
     } else {
         $socket = fsockopen('ssl://' . $server, $port, $errno, $error);
     }
     if (!$socket) {
         throw new Exception(pht('Failed to connect, #%d: %s', $errno, $error));
     }
     $ok = stream_set_blocking($socket, false);
     if (!$ok) {
         throw new Exception(pht('Failed to set stream nonblocking.'));
     }
     $this->socket = $socket;
     if ($pass) {
         $this->write("PASS {$pass}");
     }
     $this->write("NICK {$nick}");
     $this->write("USER {$user} 0 * :{$user}");
 }
开发者ID:pugong,项目名称:phabricator,代码行数:32,代码来源:PhabricatorIRCProtocolAdapter.php

示例15: __construct

 /**
  * Initialize a new stream listener
  */
 public function __construct($stream)
 {
     $this->stream = $stream;
     stream_set_blocking($this->stream, 0);
     $meta = stream_get_meta_data($this->stream);
     if (substr($meta['mode'], -1) === '+') {
         $this->writable = true;
         $this->readable = true;
     } else {
         if (strpos($meta['mode'], 'r') !== false) {
             $this->readable = true;
         }
         if (strpos($meta['mode'], 'w') !== false) {
             $this->writable = true;
         }
     }
     if ($this->readable) {
         $this->ev_read = event_new();
         event_set($this->ev_read, $this->stream, EV_READ | EV_PERSIST, array($this, '_read'));
         Loop::attachEvent($this->ev_read);
     }
     if ($this->writable) {
         $this->ev_write = event_new();
         event_set($this->ev_write, $this->stream, EV_WRITE | EV_PERSIST, array($this, '_write'));
         Loop::attachEvent($this->ev_write);
     }
 }
开发者ID:expressif,项目名称:stream,代码行数:30,代码来源:Event.php


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