stream_get_meta_data(打开的文件句柄) 拿到任何网站服务器名字,从封装协议文件指针中取得报头/元数据

时间:2022-12-26 10:45:50
$url = "http://www.sina.com/";

 function parse($url) {
if(!($fp = @fopen($url, 'rb')) ){
exit('路径错误');
}
$meta = stream_get_meta_data($fp);
foreach(array_keys($meta) as $h){
$v = $meta[$h];
echo "".$h.": ".$v."<br/>";
if(is_array($v)){
foreach(array_keys($v) as $hh){
$vv = $v[$hh];
echo "".$hh.": ".$vv."<br/>";
}
}
}
fclose($fp);
}
parse($url); /** wrapper_data: Array
0: HTTP/1.1 301 Moved Permanently
1: Server: nginx
2: Date: Mon, 27 Apr 2015 10:09:21 GMT
3: Content-Type: text/html
4: Location: http://www.sina.com.cn/
5: Expires: Mon, 27 Apr 2015 10:11:21 GMT
6: Cache-Control: max-age=120
7: Age: 11
8: Content-Length: 178
9: X-Cache: HIT from ctc.gz.1cf2.42.spool.sina.com.cn
10: Connection: close
11: HTTP/1.1 200 OK
12: Content-Type: text/html
13: Vary: Accept-Encoding
14: X-Powered-By: schi_v1.02
15: Server: nginx
16: Date: Mon, 27 Apr 2015 10:09:31 GMT
17: Last-Modified: Mon, 27 Apr 2015 10:08:29 GMT
18: Expires: Mon, 27 Apr 2015 10:10:31 GMT
19: Cache-Control: max-age=60
20: Content-Length: 575278
21: X-Cache: HIT from ctc.gz.1cf2.45.spool.sina.com.cn
22: Connection: close
wrapper_type: http
stream_type: tcp_socket
mode: rb
unread_bytes: 0
seekable:
uri: http://www.sina.com/
timed_out:
blocked: 1
eof:
*/