php錯誤提示failed to open stream
當使用php5自帶的file_get_contents方法來獲取遠程文件的時候,有時候會出現file_get_contents(): failed to open stream: HTTP request failed!這個警告信息。就跟隨本站小編一起去了解下吧,想了解更多相關信息請持續關注我們應屆畢業生考試網!
google或者baidu一下,好多這樣的'問題,解決的方法都是修改,把allow_url_fopen給啓用,改成 allow_url_fopen = On
這樣做可以解決某些人的問題,有人說在中,有這樣兩個選項:allow_url_fopen =on(表示可以通過url打開遠程文件),user_agent="PHP"(表示通過哪種腳本訪問網絡,默認前面有個 " ; " 去掉即可。)重啓服務器。
但是有些還是會有這個警告信息,想用完美的解決還差一步,還得設置裏面的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) [file]: 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 = "";
$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;
?>
相關文章
-
Jolie drops battle over perfume named Shilohy英語作文
angelina jolie has dropped her legal battle with a perfume-maker who had named her fragrance shiloh - the same as jolies youngest daughter.jolie had filed a note with the u.s. patent and trademark off -
A Letter to the Editor of a Newspaper英語四級作文
甲方:____________________乙方:____________________1.乙方有權在按照本合同的規定通過甲方網站發佈招聘廣告;2.乙方必須是具備法人資格的合法註冊、經營的企業,保證所發佈信息的真實性、合法性;3.乙方獨立承擔發佈信息所引 -
Diaspora Finance Powers Global Development美文欣賞
Diaspora Finance Powers Global DevelopmentLuis Lopez-Ramirez, a 30-year old Honduran immigrant, makes pizza.He has worked two jobs over 16 hours each day.He carefully saves his money and rents a small -
Efforts Urged to Improve Womens Reproductive Health英語閱讀
Efforts Urged to Improve Women's Reproductive HealthParliamentarians from over 100 countries are being urged to take action in improving women's reproductive health ahead of the 2015 deadline -
英語作文展示:all those friendly people
In my final year of university,I failed a very important examination for my college degree. What's worse,I was refused in a job interview, which had taken me much time to prepare. Sadness possesse -
英語閱讀範文參考:LovePeopleInAllKindsOfWeather
LovePeopleInAllKindsOfWeatherMake sure your love is unconditional. Make sure you love people in all kinds of "weather". Or else what is the use if we love a person only when he is good or she is nice? -
The Development of a Private Car英語作文
在我們平凡的日常裏,大家對作文都再熟悉不過了吧,作文是經過人的`思想考慮和語言組織,通過文字來表達一個主題意義的記敘方法。相信寫作文是一個讓許多人都頭痛的問題,下面是小編爲大家整理的The Development of a Privat -
Thinkpad筆記本開機顯示Tointerrruptnormalstartup解決方法
Thinkpad筆記本開機顯示To interrrupt normal startup的解決方法1、先等待5-6分鐘,如果系統又恢復了正常,說明可能是系統硬盤或者風扇區出了問題;2、假如過了5-6分鐘依然沒有反應,則可嘗試先拆掉筆記本電池在裝上;3、或 -
At Climate Summit, Hope for Emissions Deal美文欣賞
It's known as "the roof of the world," four thousand seven hundred meters above sea level lies the Tibetan Plateau. Its glaciers are the source of many of Asia’s most important rivers.But the ice -
人教PEP版國小五年級英語下冊Unit3Myschoolcalender.ALet’stalk
本部分學習的核心句型是:Whenistheparty?It’sinApril.教材通過Mike和張鵬對校歷上四、五月要舉行的活動的討論場景,介紹了孩子們在春天將有很多趣味性活動的情景,即四月的運動會個萬聖節聚會、五月的春遊,讓學生感知上述