i-sultan Posted August 9, 2009 Share Posted August 9, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/ Share on other sites More sharing options...
akitchin Posted August 9, 2009 Share Posted August 9, 2009 how are you calling the function? are you just calling it as get_headers() without any parameters? if so, that's likely the problem since the first parameter in the function is required. Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893965 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 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); } Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893973 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 A little detail, URL on what get_headers() function fires warning are within long array, and when I call get_headers(...) just once on dropped URLs it works but within a loop it does not ... Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893975 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 Well, have you read the error message that is returned? What does it tell you? Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893984 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 seems it tries to call internal function which fails in turn... but if i call get_headers(DROPPED_URL) it works, I am confused ... Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893987 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 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) Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893992 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 Invalid - com-foo-bar, but this link is not invalid http://sdpk.info it is in an array... When this link is represented as array element i get warning, but if i do so php -r "var_dump(get_headers('http://sdpk.info'));" it works well... Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893994 Share on other sites More sharing options...
Daniel0 Posted August 9, 2009 Share Posted August 9, 2009 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" } Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893997 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 try these links please http://www.kloop.kg http://www.dw-world.de http://blogs.mail.ru http://www.internews.fr http://http://www.spdk.kg http://www.spdk.info http://www.sdpk.kg http://www.shailoo.gov.kg Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-893999 Share on other sites More sharing options...
i-sultan Posted August 9, 2009 Author Share Posted August 9, 2009 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-894001 Share on other sites More sharing options...
i-sultan Posted August 27, 2009 Author Share Posted August 27, 2009 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 !!! Quote Link to comment https://forums.phpfreaks.com/topic/169441-get_headers-problems/#findComment-907410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.