首頁  >  文章  >  後端開發  >  php file_get_contents 的网址状态码为500时,不想让错误出现在应用服务器的error_log应该怎么做呢?

php file_get_contents 的网址状态码为500时,不想让错误出现在应用服务器的error_log应该怎么做呢?

WBOY
WBOY原創
2016-06-06 20:37:051660瀏覽

场景:
服务器根据用户输入生成网址。
通过 file_get_contents 抓取网址。
网页有可能不存在。
这种情况发生挺频繁,导致error_log出现很多PHP Warning: file_get_contents(xxxxxxxxxxxxxx): failed to open stream: HTTP request failed!

请问应该怎么做能够让这种错误不出现在error_log里呢?

回复内容:

场景:
服务器根据用户输入生成网址。
通过 file_get_contents 抓取网址。
网页有可能不存在。
这种情况发生挺频繁,导致error_log出现很多PHP Warning: file_get_contents(xxxxxxxxxxxxxx): failed to open stream: HTTP request failed!

请问应该怎么做能够让这种错误不出现在error_log里呢?

@ 完事了,再加上判断逻辑

修改php.ini 调整 display_errors 为 0, 或者调整 error_reporting 的错误等级为 error 级别以上才记录

为了使代码更加健壮,推荐使用 curl http://php.net/manual/zh/function.curl-exec.php

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn