Skip to content

Instantly share code, notes, and snippets.

@makerneo-com
Created August 14, 2013 15:02
Show Gist options
  • Select an option

  • Save makerneo-com/6231903 to your computer and use it in GitHub Desktop.

Select an option

Save makerneo-com/6231903 to your computer and use it in GitHub Desktop.
<?php
$arr = array(
'www.baidu.com',
'tieba.baidu.com',
'www.163.com',
'www.sina.com.cn',
);
$reads = array();
foreach ($arr as $k=>$r) {
$writes[] = stream_socket_client("tcp://$r:80",$errno, $errstr, 0.5);
}
$reads = NULL;
$except = NULL;
while ($writes && stream_select($reads, $writes, $except, 0.5) !== false) {
foreach ($writes as $k=>$fp) {
stream_set_timeout($fp, 2);
fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
$res = fread($fp, 2000);
$info = stream_get_meta_data($fp);
unset($writes[$k]);
fclose($fp);
var_dump($res);
var_dump($info);
var_dump($fp);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment