file_get_contents()函数报500 Internal Server Error

论坛 期权论坛     
选择匿名的用户   2021-6-2 17:58   213   0
<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 &#61; 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,&#39;Lucida Console&#39;,&#39;Liberation Mono&#39;,&#39;DejaVu sans Mono&#39;,&#39;Bitstream Vera sans Mono&#39;,&#39;Courier new&#39;,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,&#39;Lucida Console&#39;,&#39;Liberation Mono&#39;,&#39;DejaVu sans Mono&#39;,&#39;Bitstream Vera sans Mono&#39;,&#39;Courier new&#39;,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">&#61;</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)">&#39;http&#39;</span><span style="word-wrap:normal; word-break:normal; line-height:21px; margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent">&#61;&gt;</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)">&#39;header&#39;</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">&#61;&gt;</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)">&#34;User-Agent:MyAgent/1.0\r\n&#34;</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
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP