<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    php錯誤提示failed to open stream

    時間:2025-01-19 04:40:04 php語言 我要投稿
    • 相關推薦

    php錯誤提示failed to open stream

      當使用php5自帶的file_get_contents方法來獲取遠程文件的時候,有時候會出現file_get_contents(): failed to open stream: HTTP request failed!這個警告信息。就跟隨百分網小編一起去了解下吧,想了解更多相關信息請持續關注我們應屆畢業生考試網!

    php錯誤提示failed to open stream

      google或者baidu一下,好多這樣的問題,解決的方法都是修改php.ini,把allow_url_fopen給啟用,改成 allow_url_fopen = On

      這樣做可以解決某些人的問題,有人說在php.ini中,有這樣兩個選項:allow_url_fopen =on(表示可以通過url打開遠程文件),user_agent="PHP"(表示通過哪種腳本訪問網絡,默認前面有個 " ; " 去掉即可。)重啟服務器。

      但是有些還是會有這個警告信息,想用完美的解決還差一步,還得設置php.ini里面的user_agent,php默認的user_agent是PHP,我們把它改成Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)來模擬瀏覽器就可以了

      user_agent=”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”

      在工作中遇到這個問題,后完美解決,故分享給大家。

      我批量抓取chemblink的結構式發現循環后有部分圖片無法顯示,而遠程文件是存在的。

      抓取遠程文件的時候出現類似Warning: readfile(http://www.jb51.net/logo.gif) [function.readfile]: failed to open stream: HTTP request failed! 這樣的警告信息,我使用的是

      復制代碼 代碼如下:

      ob_start();

      readfile("http://www.jb51.net/logo.gif");

      $img = ob_get_contents();

      ob_end_clean();

      這樣在運行中會時不時的出現上述錯誤,我也換過file_get_contents等其他函數都沒用用,在網上查閱后發現用CURL方法抓取不會出錯

      現在比較流行使用curl

      復制代碼 代碼如下:

      <?php

      $url = "http://s.jb51.net";

      $ch = curl_init();

      curl_setopt ($ch, CURLOPT_URL, $url);

      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

      curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT,10);

      $dxycontent = curl_exec($ch);

      echo $dxycontent;

      ?>

    【php錯誤提示failed to open stream】相關文章:

    解決PHP的failed opening required問題的方法10-31

    PHP的錯誤機制總結08-15

    PHP錯誤機制的總結10-20

    PHP 的錯誤機制總結09-12

    PHP學習入門之PHP錯誤處理07-14

    PHP錯誤類型及屏蔽方法07-26

    php中屏蔽與顯示錯誤消息06-24

    2017年PHP錯誤總結范文10-16

    win8系統Err-Failed錯誤解決方法05-16

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人