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


PHP stream_set_timeout函数代码示例

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


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

示例1: 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

示例2: _recv

 protected function _recv()
 {
     stream_set_timeout($this->_fp, 0, $this->_timeout_recv);
     $data = fread($this->_fp, 24);
     $info = stream_get_meta_data($this->_fp);
     if ($info['timed_out']) {
         return FALSE;
     }
     $array = $this->_show_request($data);
     if ($array['bodylength']) {
         $bodylength = $array['bodylength'];
         $data = '';
         while ($bodylength > 0) {
             $recv_data = fread($this->_fp, $bodylength);
             $bodylength -= strlen($recv_data);
             $data .= $recv_data;
         }
         if ($array['extralength']) {
             $extra_unpacked = unpack('Nint', substr($data, 0, $array['extralength']));
             $array['extra'] = $extra_unpacked['int'];
         }
         $array['key'] = substr($data, $array['extralength'], $array['keylength']);
         $array['body'] = substr($data, $array['extralength'] + $array['keylength']);
     }
     return $array;
 }
开发者ID:aatty,项目名称:Heroku-Memcachier,代码行数:26,代码来源:Memcachesasl.php

示例3: connect

 public function connect($ip, $port)
 {
     $this->remoteip = $ip;
     $this->remoteport = $port;
     $errno = 0;
     $errstr = '';
     logger::debug("Connecting to %s:%d", $ip, $port);
     $this->state = SOCKSTATE_CONNECTING;
     $this->fsh = fsockopen($ip, $port, $errno, $errstr);
     if ($errno) {
         logger::warning("Socket error: %d %s (%s:%d)", $errno, $errstr, $ip, $port);
         $this->state = SOCKSTATE_ERROR;
         return false;
     } else {
         if (!$this->fsh) {
             $this->state = SOCKSTATE_ERROR;
             logger::warning("No socket handle returned but no error indicated");
             return false;
         }
         logger::debug("Socket connected to %s:%d", $ip, $port);
         stream_set_timeout($this->fsh, 0, 200);
         $this->state = SOCKSTATE_CONNECTED;
         return true;
     }
 }
开发者ID:noccy80,项目名称:lepton-ng,代码行数:25,代码来源:sockets.php

示例4: connect

 function connect()
 {
     $this->online_start = microtime(true);
     $this->main->log('Connecting to ' . $this->info['address'] . '...', __CLASS__);
     $this->socket = @fsockopen($this->info['address'], $this->info['port'], $erno, $errstr, 30);
     @stream_set_blocking($this->socket, false);
     @stream_set_timeout($this->socket, $this->listen_timeout);
     if ($this->state() == false) {
         $this->main->log('Could not connect to ' . $this->info['address'] . ': (' . $erno . ') ' . $errstr, __CLASS__);
         $this->reconnect();
     } else {
         $this->retry_count = 0;
         $this->main->log('Connection to IRC-server established', __CLASS__);
         //Connection stuff
         if (!empty($this->info['pass'])) {
             $this->main->log('Sending stored password', __CLASS__);
             $this->main->send_data('PASS ' . $this->info['pass'], IRCINE_PRIO_CRITICAL);
         }
         $this->main->log('Authenticating to IRC-server', __CLASS__);
         $this->nickname(Mootyconf::get_value('deerkins::nick'));
         $this->main->log('Sending ident info', __CLASS__);
         $this->main->send_data('USER ' . $this->info['ident'] . ' ' . $this->info['address'] . ' * :' . $this->info['realname'], IRCINE_PRIO_CRITICAL);
         // Idents with server
         $this->main->log('Connection to ' . $this->info['address'] . ' succeeded!', __CLASS__);
         $this->listen();
     }
 }
开发者ID:unnes,项目名称:deerkins,代码行数:27,代码来源:ircine.connection.php

示例5: dial

 /**
  * Initialize connection to JSON-RPC server.
  *
  * @throws Exception\JsonRPCException
  */
 function dial()
 {
     $conn = @fsockopen($this->host, $this->port, $errorNumber, $errorString, 5);
     if (!$conn) {
         throw new JsonRPCException(sprintf('An error appeared while connecting to RPC server: %s (%d)', $errorNumber, $errorString), $errorNumber);
     }
     $request = 'CONNECT ' . $this->path . ' HTTP/1.0' . "\n";
     if (array_key_exists('dial_headers', $this->options)) {
         foreach ($this->options['dial_headers'] as $header => $value) {
             $request .= $header . ': ' . $value . "\n";
         }
     }
     @fwrite($conn, $request . "\n");
     stream_set_timeout($conn, 0, 3000);
     do {
         $line = @fgets($conn);
     } while ($line !== false && empty($line));
     $success = 'HTTP/1.0 200 Connected';
     if ($line === false) {
         throw new JsonRPCException('An error appeared while reading from RPC server');
     } else {
         if (substr($line, 0, strlen($success)) != $success) {
             @fclose($conn);
             throw new JsonRPCException(sprintf('Unexpected HTTP response while connecting: %s', $line));
         }
     }
     $this->connection = $conn;
 }
开发者ID:sroze,项目名称:discoverd-client,代码行数:33,代码来源:JsonRPCClient.php

示例6: InitUrlSocket

 private function InitUrlSocket()
 {
     $i = $CreateCount = $ErrCount = 0;
     $errno = $errstr = 0;
     foreach ($this->Sockets as $Key => $UrlUnit) {
         $Urls = $UrlUnit['Urls'];
         $Port = empty($Urls['port']) ? '80' : $Urls['port'];
         $s = stream_socket_client($Urls['host'] . ':' . $Port, $errno, $errstr, $this->ConnectTimeout, STREAM_CLIENT_ASYNC_CONNECT | STREAM_CLIENT_CONNECT);
         if ($s) {
             stream_set_timeout($s, 0, $this->StreamTimeout);
             $this->Sockets[$Key]['Socket'] = $s;
             $this->Sockets[$Key]['Data'] = '';
             $this->Sockets[$Key]['Succ'] = false;
             $this->Sockets[$Key]['HttpStates'] = array();
             $this->Sockets[$Key]['State'] = 0;
             $this->Sockets[$Key]['Location'] = '';
             $this->Sockets[$Key]['DataLen'] = 0;
             $CreateCount++;
         } elseif ($ErrCount == 3) {
             exit('cannot connection internet');
         } else {
             unset($this->Sockets[$Key]);
             $ErrCount++;
         }
     }
     return $CreateCount;
 }
开发者ID:huangwei2wei,项目名称:kfxt,代码行数:27,代码来源:HJMultiSocket.class.php

示例7: http_send

function http_send($_url, $_body)
{
    $errno = 0;
    $errstr = '';
    $timeout = 10;
    $fp = fsockopen(_IP_, _PORT_, $errno, $errstr, $timeout);
    if (!$fp) {
        return FALSE;
    }
    $_head = "POST /" . $_url . " HTTP/1.1\r\n";
    $_head .= "Host: " . _IP_ . ":" . _PORT_ . "\r\n";
    $_head .= "Content-Type: Text/plain\r\n";
    if (!$_body) {
        $body_len = 0;
    } else {
        $body_len = strlen($_body);
    }
    $send_pkg = $_head . "Content-Length:" . $body_len . "\r\n\r\n" . $_body;
    ilog(iLOG_INFO, "    -----> http_send url: " . $_url);
    ilog(iLOG_INFO, "    -----> http_send body: " . $_body);
    if (fputs($fp, $send_pkg) === FALSE) {
        return FALSE;
    }
    //设置3s超时
    stream_set_timeout($fp, 3);
    while (!feof($fp)) {
        ilog(iLOG_INFO, "    -----> rsp: " . fgets($fp, 128));
    }
    if ($fp) {
        fclose($fp);
    }
    return TRUE;
}
开发者ID:yonglinchen,项目名称:shopping,代码行数:33,代码来源:ihttp.php

示例8: setSocketTimeout

 public function setSocketTimeout($seconds)
 {
     $this->config['socket_timeout'] = $seconds;
     if (isset($this->connection) && $seconds > 0) {
         stream_set_timeout($this->connection, $seconds);
     }
 }
开发者ID:TheProjecter,项目名称:skeleton,代码行数:7,代码来源:Smtp.php

示例9: connect

 /**
  * Connects and authenticates to SMTP server.
  * @return void
  */
 private function connect()
 {
     $this->connection = @fsockopen(($this->secure === 'ssl' ? 'ssl://' : '') . $this->host, $this->port, $errno, $error, $this->timeout);
     if (!$this->connection) {
         throw new SmtpException($error, $errno);
     }
     stream_set_timeout($this->connection, $this->timeout, 0);
     $this->read();
     // greeting
     $self = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost';
     $this->write("EHLO {$self}");
     if ((int) $this->read() !== 250) {
         $this->write("HELO {$self}", 250);
     }
     if ($this->secure === 'tls') {
         $this->write('STARTTLS', 220);
         if (!stream_socket_enable_crypto($this->connection, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
             throw new SmtpException('Unable to connect via TLS.');
         }
         $this->write("EHLO {$self}", 250);
     }
     if ($this->username != NULL && $this->password != NULL) {
         $this->write('AUTH LOGIN', 334);
         $this->write(base64_encode($this->username), 334, 'username');
         $this->write(base64_encode($this->password), 235, 'password');
     }
 }
开发者ID:anagio,项目名称:woocommerce,代码行数:31,代码来源:SmtpMailer.php

示例10: __construct

 /**
  * @param string $host
  * @param int $port
  * @param int $connectTimeout
  */
 public function __construct($host, $port, $connectTimeout)
 {
     if (!($this->_socket = @fsockopen($host, $port, $errno, $errstr, $connectTimeout))) {
         throw new Pheanstalk_Exception_ConnectionException($errno, $errstr);
     }
     stream_set_timeout($this->_socket, self::SOCKET_TIMEOUT);
 }
开发者ID:nauzet18,项目名称:consig,代码行数:12,代码来源:NativeSocket.php

示例11: open

 public function open($host, $port, $transport = 'tcp')
 {
     // if a socket is current open then close it
     $this->close();
     if (($ip = filter_var($host, FILTER_VALIDATE_IP)) !== false) {
         $this->host = $ip;
     } elseif (($ip = gethostbyname($host)) != $host) {
         $this->host = $ip;
     } else {
         throw new Exception('Unable to resolve host: ' . $host);
     }
     $this->port = filter_var($port, FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => 65535)));
     if (!$this->port) {
         throw new Exception('Invalid Port: ' . $port);
     }
     $err = 0;
     $msg = '';
     $this->stream = fsockopen("{$transport}://{$this->host}", $this->port, $err, $msg, $this->timeout);
     if (!$this->isOpen()) {
         throw new Exception("Unable to open socket: {$msg}", $err);
     }
     stream_set_timeout($this->stream, $this->timeout);
     stream_set_blocking($this->stream, $this->block);
     return $this;
 }
开发者ID:simon-downes,项目名称:spf,代码行数:25,代码来源:Socket.php

示例12: __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

示例13: scrape

 public function scrape($url, $infohash)
 {
     if (!is_array($infohash)) {
         $infohash = array($infohash);
     }
     foreach ($infohash as $hash) {
         if (!preg_match('#^[a-f0-9]{40}$#i', $hash)) {
             throw new ScraperException('Invalid infohash: ' . $hash . '.');
         }
     }
     $url = trim($url);
     if (preg_match('%(http://.*?/)announce([^/]*)$%i', $url, $m)) {
         $url = $m[1] . 'scrape' . $m[2];
     } else {
         if (preg_match('%(http://.*?/)scrape([^/]*)$%i', $url, $m)) {
         } else {
             throw new ScraperException('Invalid tracker url.');
         }
     }
     $sep = preg_match('/\\?.{1,}?/i', $url) ? '&' : '?';
     $requesturl = $url;
     foreach ($infohash as $hash) {
         $requesturl .= $sep . 'info_hash=' . rawurlencode(pack('H*', $hash));
         $sep = '&';
     }
     ini_set('default_socket_timeout', $this->timeout);
     $rh = @fopen($requesturl, 'r');
     // var_dump($url);
     if (!$rh) {
         throw new ScraperException('Could not open HTTP connection.', 0, true);
     }
     stream_set_timeout($rh, $this->timeout);
     $return = '';
     $pos = 0;
     while (!feof($rh) && $pos < $this->maxreadsize) {
         $return .= fread($rh, 1024);
     }
     fclose($rh);
     if (!substr($return, 0, 1) == 'd') {
         throw new ScraperException('Invalid scrape response.');
     }
     $lightbenc = new lightbenc();
     $arr_scrape_data = $lightbenc->bdecode($return);
     $torrents = array();
     foreach ($infohash as $hash) {
         $ehash = pack('H*', $hash);
         if (isset($arr_scrape_data['files'][$ehash])) {
             if (array_key_exists('downloaded', $arr_scrape_data['files'][$ehash])) {
                 $completed = $arr_scrape_data['files'][$ehash]['downloaded'];
             } else {
                 $completed = "0";
             }
             $torrents[$hash] = array('infohash' => $hash, 'seeders' => (int) $arr_scrape_data['files'][$ehash]['complete'], 'completed' => (int) $completed, 'leechers' => (int) $arr_scrape_data['files'][$ehash]['incomplete']);
         } else {
             $torrents[$hash] = false;
         }
     }
     // var_dump($torrents);
     return $torrents;
 }
开发者ID:doio,项目名称:Bittytorrent,代码行数:60,代码来源:httptscraper.php

示例14: connect

 public function connect($host, $port = false, $tval = 30)
 {
     if ($this->connected) {
         return true;
     }
     set_error_handler(array($this, 'catchWarning'));
     $this->pop_conn = fsockopen($host, $port, $errno, $errstr, $tval);
     restore_error_handler();
     if ($this->error && $this->do_debug >= 1) {
         $this->displayErrors();
     }
     if ($this->pop_conn == false) {
         $this->error = array('error' => "Failed to connect to server {$host} on port {$port}", 'errno' => $errno, 'errstr' => $errstr);
         if ($this->do_debug >= 1) {
             $this->displayErrors();
         }
         return false;
     }
     if (version_compare(phpversion(), '5.0.0', 'ge')) {
         stream_set_timeout($this->pop_conn, $tval, 0);
     } else {
         if (substr(PHP_OS, 0, 3) !== 'WIN') {
             socket_set_timeout($this->pop_conn, $tval, 0);
         }
     }
     $pop3_response = $this->getResponse();
     if ($this->checkResponse($pop3_response)) {
         $this->connected = true;
         return true;
     }
     return false;
 }
开发者ID:ChainBoy,项目名称:wxfx,代码行数:32,代码来源:class.pop3.php

示例15: send

 /**
  * Send data through the socket and listen for a return
  * @param string $msg Data to send
  * @param string $type The type of data to return (array or string)
  * @return string|array
  */
 function send($msg, $type = '')
 {
     // Set a short timeout to prevent long hangs
     stream_set_timeout($this->handle, 2);
     // Send message over connection
     fwrite($this->handle, $msg);
     // Check what type is required
     if ($type == 'array') {
         // If array loop and create array
         $response = array();
         $line_num = 0;
         while (!feof($this->handle)) {
             if (($response[$line_num] = fgets($this->handle, 4096)) === false) {
                 break;
             } else {
                 $line_num++;
             }
         }
         // Return response as array
         return $response;
     } elseif ($type == 'string') {
         // If string, loop and create string
         $response = '';
         while (!feof($this->handle)) {
             $response .= fgets($this->handle, 4096);
         }
         // Return response as string
         return $response;
     } else {
         // If anything else, return nothing but a true
         return true;
     }
 }
开发者ID:jensz12,项目名称:PHP-Last.fm-API,代码行数:39,代码来源:Socket.php


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