我正在编写一个简单的PHP脚本,但我发现了一个奇怪的行为(不是错误):stream_get_meta_data()的返回值格式在不同平台上不一致。
简化的示例代码如下:
<?php
$handle = fopen("http://www.example.com", "r");
if ($handle) {
$dump = fgets($handle);
$stream_meta = stream_get_meta_data( $handle );
echo print_r( $stream_meta, true );
fclose($handle);
}
?>
这个PHP脚本应该在我的QNAP TS-269 NAS上运行。正如其他人一样,我在我的电脑上编写并测试代码,然后转移到NAS。
当我在电脑上执行此代码时,我得到了这个结果:
Array
(
[timed_out] =>
[blocked] => 1
[eof] =>
[wrapper_data] => Array
(
[0] => HTTP/1.0 200 OK
[1] => Cache-Control: max-age=604800
[2] => Content-Type: text/html
[3] => Date: Mon, 30 Jan 2017 08:44:14 GMT
[4] => Etag: "359670651+ident"
[5] => Expires: Mon, 06 Feb 2017 08:44:14 GMT
[6] => Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
[7] => Server: ECS (rhv/818F)
[8] => Vary: Accept-Encoding
[9] => X-Cache: HIT
[10] => x-ec-custom-error: 1
[11] => Content-Length: 1270
[12] => Connection: close
)
[wrapper_type] => http
[stream_type] => tcp_socket/ssl
[mode] => r
[unread_bytes] => 1254
[seekable] =>
[uri] => http://www.example.com
)
但在NAS上,结果变为:
Array
(
[wrapper_data] => Array
(
[headers] => Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: max-age=604800
[2] => Content-Type: text/html
[3] => Date: Mon, 30 Jan 2017 08:44:25 GMT
[4] => Etag: "359670651+ident"
[5] => Expires: Mon, 06 Feb 2017 08:44:25 GMT
[6] => Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
[7] => Server: ECS (rhv/818F)
[8] => Vary: Accept-Encoding
[9] => X-Cache: HIT
[10] => x-ec-custom-error: 1
[11] => Content-Length: 1270
)
[readbuf] => Resource id #6
)
[wrapper_type] => cURL
[stream_type] => cURL
[mode] => r
[unread_bytes] => 1254
[seekable] =>
[uri] => http://www.example.com
[timed_out] =>
[blocked] => 1
[eof] =>
)
$result['wrapper_data']
的数组结构不同。第一个结果(在PC上)与PHP官方网站上的示例相匹配。在NAS上,这些HTTP响应标头在额外级别$result['wrapper_data']['header']
下收集。
PC版本为5.6.28,NAS版本为5.3.29。
这是正常行为吗?由于PHP版本不同或什么?
答案 0 :(得分:0)
好吧,似乎你有两个不同的包装器(&#39; wrapper_type&#39;字段):你的PC上的http和NAS上的cURL。也许您在一种情况下将脚本作为Apache模块运行,而在另一种情况下以CLI模式运行?
UPD: http://php.net/manual/en/curl.installation.php &#34;从PHP 4.3.0开始,您可以配置PHP以使用cURL进行URL流--with-curlwrappers。自PHP 5.5.0起,此功能已移至PECL&#34;