get-headers

Exception handling with get_meta_tags() & get_headers()?

你。 提交于 2019-12-07 15:06:32
问题 In PHP, I am using get_meta_tags() and get_headers() , however, when there is a 404, those two functions throw a warning. Is there any way for me to catch it? Thanks! 回答1: get_headers does not throw a Warning/Error on 404, but get_meta_tags does. So you can check the header response and do something, when it's not OK: $url = 'http://www.example.com/'; $headers = array(); $metatags = array(); $validhost = filter_var(gethostbyname(parse_url($url,PHP_URL_HOST)), FILTER_VALIDATE_IP); if(

Using get_headers with a proxy

冷暖自知 提交于 2019-12-06 03:47:13
问题 In order to check if an URL is an image, I use the PHP function get_headers . In normal conditions, it works very well. But when I'm behind a proxy, it causes a timeout exception. I had the same problem with file_put_contents but I solved it by adding a context parameter. However, the get_headers function hasn't a similar argument. Do you know how to do please ? 回答1: Use stream_context_set_default function. This blog post explains how to use it. Here is the code from that page. <?php // Edit

Exception handling with get_meta_tags() & get_headers()?

吃可爱长大的小学妹 提交于 2019-12-05 22:41:59
In PHP, I am using get_meta_tags() and get_headers() , however, when there is a 404, those two functions throw a warning. Is there any way for me to catch it? Thanks! get_headers does not throw a Warning/Error on 404, but get_meta_tags does. So you can check the header response and do something, when it's not OK: $url = 'http://www.example.com/'; $headers = array(); $metatags = array(); $validhost = filter_var(gethostbyname(parse_url($url,PHP_URL_HOST)), FILTER_VALIDATE_IP); if($validhost){ // get headers only when Domain is valid $headers = get_headers($url, 1); if(substr($headers[0], 9, 3) =

php get_headers a good way to tell if a site is up?

£可爱£侵袭症+ 提交于 2019-12-04 20:21:53
I'm still fairly new to php, can you comment on whether the code below is any good to tell if a site is up or down and if it might not be suitable the reasons why and better altneratives? Thanks in advance. $siteHeader = @get_headers($url , 1); if ($siteHeader > 1) { $siteUp = true; } else { $siteUp = false; } i use curl, but thats just me: function check($url, $ignore = '') { $agent = "Mozilla/4.0 (B*U*S)"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_VERBOSE, false); curl_setopt($ch, CURLOPT_TIMEOUT, 45); curl

Something faster than get_headers()

风格不统一 提交于 2019-12-04 09:33:53
问题 I'm trying to make a PHP script that will check the HTTP status of a website as fast as possible. I'm currently using get_headers() and running it in a loop of 200 random urls from mysql database. To check all 200 - it takes an average of 2m 48s. Is there anything I can do to make it (much) faster? (I know about fsockopen - It can check port 80 on 200 sites in 20s - but it's not the same as requesting the http status code because the server may responding on the port - but might not be

Using get_headers with a proxy

隐身守侯 提交于 2019-12-04 08:29:47
In order to check if an URL is an image, I use the PHP function get_headers . In normal conditions, it works very well. But when I'm behind a proxy, it causes a timeout exception. I had the same problem with file_put_contents but I solved it by adding a context parameter. However, the get_headers function hasn't a similar argument. Do you know how to do please ? Use stream_context_set_default function. This blog post explains how to use it. Here is the code from that page. <?php // Edit the four values below $PROXY_HOST = "proxy.example.com"; // Proxy server address $PROXY_PORT = "1234"; //