Jump to content

get_headers() problems


i-sultan

Recommended Posts

Hi all. I have a small problem with get_headers() function, sometimes it does not work adequate e.g. getting headers of working web resource it fires warning like this

 

Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/sultan/Http/monitor2/worker.php on line 66

 

Call Stack:

    0.0002    105168  1. {main}() /home/sultan/Http/monitor2/monitor.php:0

    0.0270    276416  2. include('/home/sultan/Http/monitor2/worker.php') /home/sultan/Http/monitor2/monitor.php:9

  358.8022    311040  3. get_headers() /home/sultan/Http/monitor2/worker.php:66

 

is there any issues ? Is it possible to avoid situations like this ? PLEASE HELP SOON :)

 

 

Thank in advance :)

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/
Share on other sites

I am calling it with parameters (even clarified urls) :)

Code

for ( $i = 0; $i < count($links); $i++ ) {

echo "\n====================LINK:".$links[$i]."=======================\n\n";

if ( get_headers('http://'.$links[$i]) )

try {

$data = get_headers('http://'.$links[$i]);

 

print_r($data);

} catch (Exception $e) { }

 

sleep(2); }

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893973
Share on other sites

Well, maybe you could tell me why the first command here returns a value and why the second gives the error you get?

 

daniel@daniel0:~$ php -r "var_dump(get_headers('http://www.phpfreaks.com'));"
array(10) {
  [0]=>
  string(15) "HTTP/1.1 200 OK"
  [1]=>
  string(35) "Date: Sun, 09 Aug 2009 09:29:50 GMT"
  [2]=>
  string(25) "Server: Apache/2.2.8 (EL)"
  [3]=>
  string(103) "Set-Cookie: phpfreaks_session=91gfcfoamietsvqnbc0ttuv783; expires=Mon, 09 Aug 2010 09:29:50 GMT; path=/"
  [4]=>
  string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
  [5]=>
  string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  [6]=>
  string(16) "Pragma: no-cache"
  [7]=>
  string(32) "Vary: Accept-Encoding,User-Agent"
  [8]=>
  string(17) "Connection: close"
  [9]=>
  string(38) "Content-Type: text/html; charset=UTF-8"
}

daniel@daniel0:~$ php -r "var_dump(get_headers('http://www.lasjdlaksjd-does-not-exist.com-foo-bar'));"
PHP Warning:  get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1
PHP Warning:  get_headers(http://www.lasjdlaksjd-does-not-exist.com-foo-bar): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in Command line code on line 1
bool(false)

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893992
Share on other sites

Well, obviously your code is broken:

 

daniel@daniel0:~$ cat | php
<?php
$sites = array('http://sdpk.info');
foreach ($sites as $site) {
var_dump(get_headers($site));
}
^D
array(15) {
  [0]=>
  string(30) "HTTP/1.1 301 Moved Permanently"
  [1]=>
  string(35) "Date: Sun, 09 Aug 2009 09:51:57 GMT"
  [2]=>
  string(14) "Server: Apache"
  [3]=>
  string(14) "Location: /ru/"
  [4]=>
  string(17) "Content-Length: 0"
  [5]=>
  string(23) "Content-Type: text/html"
  [6]=>
  string(15) "HTTP/1.1 200 OK"
  [7]=>
  string(35) "Date: Sun, 09 Aug 2009 09:51:57 GMT"
  [8]=>
  string(14) "Server: Apache"
  [9]=>
  string(62) "Set-Cookie: PHPSESSID=7b66914b01f789442dc1cfbbbda86785; path=/"
  [10]=>
  string(38) "Expires: Thu, 19 Nov 1981 08:52:00 GMT"
  [11]=>
  string(77) "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
  [12]=>
  string(16) "Pragma: no-cache"
  [13]=>
  string(17) "Connection: close"
  [14]=>
  string(23) "Content-Type: text/html"
}

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893997
Share on other sites

I see such response

 

...

...

...

====================LINK:www.spdk.info=======================

 

 

Warning: get_headers(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/sultan/Http/monitor2/worker.php on line 66

 

Call Stack:

    0.0002    105168  1. {main}() /home/sultan/Http/monitor2/monitor.php:0

    0.0253    214960  2. include('/home/sultan/Http/monitor2/worker.php') /home/sultan/Http/monitor2/monitor.php:9

  20.7031    233680  3. get_headers() /home/sultan/Http/monitor2/worker.php:66

 

 

Warning: get_headers(http://www.spdk.info): failed to open stream: No such file or directory in /home/sultan/Http/monitor2/worker.php on line 66

 

Call Stack:

    0.0002    105168  1. {main}() /home/sultan/Http/monitor2/monitor.php:0

    0.0253    214960  2. include('/home/sultan/Http/monitor2/worker.php') /home/sultan/Http/monitor2/monitor.php:9

  20.7031    233680  3. get_headers() /home/sultan/Http/monitor2/worker.php:66

 

 

====================LINK:www.sdpk.kg=======================

 

Array

(

    [0] => HTTP/1.1 301 Moved Permanently

    [1] => Date: Sun, 09 Aug 2009 10:03:21 GMT

    [2] => Server: Apache

    [3] => Location: /ru/

    [4] => Content-Length: 0

    [5] => Content-Type: text/html

    [6] => HTTP/1.1 200 OK

    [7] => Date: Sun, 09 Aug 2009 10:03:21 GMT

    [8] => Server: Apache

    [9] => Set-Cookie: PHPSESSID=fad3fe28142ca20b8a1b3644a65bec9b; path=/

    [10] => Expires: Thu, 19 Nov 1981 08:52:00 GMT

    [11] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

    [12] => Pragma: no-cache

    [13] => Connection: close

    [14] => Content-Type: text/html

)

 

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-894001
Share on other sites

  • 3 weeks later...

:) Hi all I am sorry but solution may be interesting for someone... I solved this problem almost 2 weeks ago but forgot a bit so now my solution is just use function gethostbyname() to get IP address of host and then use get_headers() function...

  1#!/usr/bin/php -q
  2 <?php
  3     $links  = array(
  4                     'www.kg',
  5                     'www.inkar.info',
  6                     'www.sdpk.info',
  7                     'www.sdpk.kg',
  8                     'www.google.com',
  9                     'www.google.tre'
10                     );
11 
12     for ( $i = 0; $i < count($links); $i++ ) {
13         $ip = gethostbyname($links[$i]);
14 
15         $valid_link = 'http://'.$ip;
16 
17         if ( preg_match('/^\d+/', $ip) == 0 ) {
18             print "Unable to resolve address...\n";
19 
20             continue;
21         }
22 
23         printf("Link:%s; IP:%s\n", $links[$i], $ip);
24         print_r(get_headers($valid_link));
25     }

 

:) thanks for all !!! :)

Link to comment
https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-907410
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.