您好,欢迎访问一九零五行业门户网

PHP 并发获取(stream_select)信息程序代码_PHP教程

$host) {$errno = 0;$errstr = ;$s = stream_socket_client($host:80, $errno, $errstr, $timeout,stream_client_async_connect|stream_client_connect);if ($s) {   $sockets[$id] = $s;   $status[$id] = in progress;} else {   $status[$id] = failed, $errno $errstr;}$retdata[$id] = ;}/* now, wait for the results to come back in */while (count($sockets)) {$read = $write = $sockets;    /* this is the magic function - explained below */$n = stream_select($read, $write, $e, $timeout);if ($n > 0) {     /* readable sockets either have data for us, or are failed connection attempts */   foreach ($read as $r) {    $id = array_search($r, $sockets);    $data = fread($r, 8192);    if (strlen($data) == 0) {     if ($status[$id] == in progress) {      $status[$id] = failed to connect;     }     fclose($r);     unset($sockets[$id]);    } else {     $retdata[$id] .= $data;    }   }   /* writeable sockets can accept an http request */   foreach ($write as $w) {    if(!is_resource($w))continue;    $id = array_search($w, $sockets);    fwrite($w, get / http/1.0 host: .$hosts[$id]. );    $status[$id] = waiting for response;   }} else {     /* timed out waiting; assume that all hosts associated     * with $sockets are faulty */   foreach ($sockets as $id => $s) {    $status[$id] = timed out . $status[$id];   }   break;}}foreach ($hosts as $id => $host) {#echo host: $host ;#echo status: . $status[$id] . ;#echo retdata: . $retdata[$id] . ;$strs = explode( ,$retdata[$id],2);echo isset($strs[1])?$strs[1]:$retdata[$id];}function debug($i){var_dump($i);var_dump(gettype($i));var_dump(is_resource($i));}?>
http://www.bkjia.com/phpjc/486113.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/486113.htmltecharticle?php $url = www.ite5e.com; if(array_key_exists(url,$_get)){ $url = $_get[url]; } $hosts = array(www.xunlei.com, www.qq.com, www.163.com,www.baidu.com,www.kaixin.com,vi...
其它类似信息

推荐信息