php_guy Posted July 6, 2007 Share Posted July 6, 2007 Hey guys, I'm making a script to read a certian file in 10 different machines. The problem is: If a machine is down, or inaccessible, then PHP will continue to "try to access" that file until a timeout occurs. Is there a way to "ping" a machine to see if it exists, without having to wait for a timout? Currently, I'm using the following code: <?php $siteName = "//box245"; if(fsockopen($siteName, 80, $errno, $errstr, 5)) { echo "Server is up! Responded within 5 seconds."; } else { echo "Server is down! Didn't respond within 5 seconds."; } ?> However, I keep getting the following errors: Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\webapps\foo.php on line 5 Warning: fsockopen() [function.fsockopen]: unable to connect to //box245:80 (Unknown error) in C:\webapps\foo.php on line 5 Server is down! Didn't respond within 5 seconds. Any ideas?? I don't mind using another method, either. Essentially, the end goal is to be able to determine whether a machine is up or not, so that if it's not, I won't bother trying to open files on that box. Thanks! Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/ Share on other sites More sharing options...
php_guy Posted July 6, 2007 Author Share Posted July 6, 2007 One problem was that I needed to remove the double-backslashes, so $siteName = "box245" But it still only works with my own machine, but not another one Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/#findComment-291412 Share on other sites More sharing options...
php_guy Posted July 6, 2007 Author Share Posted July 6, 2007 Also, I can ping these machines fine on the command prompt (e.g. C:\> ping myboxname) Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/#findComment-291435 Share on other sites More sharing options...
per1os Posted July 6, 2007 Share Posted July 6, 2007 Hey guys, I'm making a script to read a certian file in 10 different machines. The problem is: If a machine is down, or inaccessible, then PHP will continue to "try to access" that file until a timeout occurs. Is there a way to "ping" a machine to see if it exists, without having to wait for a timout? Currently, I'm using the following code: <?php $siteName = "//box245"; if(fsockopen($siteName, 80, $errno, $errstr, 5)) { echo "Server is up! Responded within 5 seconds."; } else { echo "Server is down! Didn't respond within 5 seconds."; } ?> However, I keep getting the following errors: Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\webapps\foo.php on line 5 Warning: fsockopen() [function.fsockopen]: unable to connect to //box245:80 (Unknown error) in C:\webapps\foo.php on line 5 Server is down! Didn't respond within 5 seconds. Any ideas?? I don't mind using another method, either. Essentially, the end goal is to be able to determine whether a machine is up or not, so that if it's not, I won't bother trying to open files on that box. Thanks! You will always have to wait for a timeout on a ping. Even if you were to use your computers ping command, it generally tries 3 times, in about 10 seconds or so depending if there was a response. If there is no response it takes like 20 seconds. There is no easy way to determine if the server is down, even the 5 seconds could be flawed as it may take 6 seconds for the server to respond. I think your SOL. Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/#findComment-291438 Share on other sites More sharing options...
php_guy Posted July 6, 2007 Author Share Posted July 6, 2007 Hey, thanks for the reply. Well, I just tried it on another box, which I hooked up to the network just now, and my original code worked. So I'm guessing that there are some firewalls or settings on my original machines that I tried, which prevent fsocketopen() from establishing a connection. But then, I thought, "Why did ping <myServer> work??".... What is DOS's "ping" command doing that fsocketopen does not? Does anyone know if there's a method to mimic what "ping" does? (without making a call to PHP's system() function to run it externally) Thanks! Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/#findComment-291467 Share on other sites More sharing options...
php_guy Posted July 9, 2007 Author Share Posted July 9, 2007 Also, even if I set the timeout to a higher number, like 30 or 50 seconds, etc. it still does not respond. Is there a way to mimic DOS's ping functionality in PHP? Link to comment https://forums.phpfreaks.com/topic/58743-access-network-files/#findComment-293308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.