0

我有一个网站的 twitter 提要,它在过去 5 分钟内一直没有问题,但是突然间它停止并抛出了这个错误:

Warning: file_get_contents(http://api.twitter.com/1/statuses/user_timeline/xxx.json)

[function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /home/fhlinux009/t/xxx.co.uk/user/htdocs/wp-content/themes/xxx/homepageTest.php on line 100

将敏感数据替换为 xxx。

代码是:

<?php
    $username='xxx'; // set user name
    $format='json'; // set format
    $tweet=json_decode(file_get_contents("http://api.twitter.com/1/statuses/
    user_timeline/{$username}.{$format}")); // get tweets 
    //and decode them into a variable
?>

<div id="sliderId">
  <ul>
    <li class="current"><?php echo $tweet[0]->text; ?></li>
    <li><?php echo $tweet[1]->text; ?></li>
    <li><?php echo $tweet[2]->text; ?></li>
  </ul>
</div>

我不得不使用这种方法来处理滑块。我不确定它为什么停止工作。

更新:如果请求耗尽服务器,是否可以一次将 file_get_contents 的结果缓存大约 15 / 30 分钟?

4

1 回答 1

0
  1. 检查网址,在浏览器中手动执行。
  2. 如果 url 在浏览器中有效allow_url_fopen,请在 php ini 中启用设置并重新启动服务器。
于 2013-02-01T11:57:57.577 回答