Jump to content

Access network files?


php_guy

Recommended Posts

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

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

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

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.