<span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">前几天,调试网站时发现,同样的代码,在两个不同的服务器上有不同的运行结果:一个运行结果没有任何问题,另外一个却显示</span>
<span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">599 Internal Server</span>
<span style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)"> Error。</span>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
于是,开始各种Debug,绕了一大圈才发现是file_get_contents()函数的问题,由于不同的php版本对其的支持不同。
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
没问题的php版本是5.4.7,
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
$jsonData = file_get_contents($url);
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
直接返回相应的结果
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
<br>
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
有问题的php版本是5.3.10
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
在网上搜了一下,碰到类似问题的人很多,推荐的方法是:
</div>
<div style="color:rgb(70,70,70); font-family:simsun; font-size:14px; line-height:21px; background-color:rgb(188,211,229)">
<pre style="white-space:normal; margin-top:0px; margin-bottom:10px; padding:5px; border:0px; vertical-align:baseline; background-color:rgb(238,238,238); font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu sans Mono','Bitstream Vera sans Mono','Courier new',monospace,serif; overflow:auto; width:auto; max-height:600px; word-wrap:normal; line-height:17.804800033569336px"><code style="margin:0px; padding:0px; border:0px; vertical-align:baseline; font-family:Consolas,Menlo,Monaco,'Lucida Console','Liberation Mono','DejaVu sans Mono','Bitstream Vera sans Mono','Courier new',monospace,serif; white-space:inherit"><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">$opts <wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> <wbr></wbr>array</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">(</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'http'</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=></span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">array</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">(</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">'header'</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> <wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">=></span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> <wbr></wbr></span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; color:rgb(128,0,0)">"User-Agent:MyAgent/1.0\r\n"</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">));</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent"> <wbr></wbr></span></code></pre>
<pre style |
|