From: Daniel Brown on
On Sat, Dec 19, 2009 at 19:13, Angus Mann <angusmann(a)pobox.com> wrote:
> Hi all.
>
> I'w writing a PHP app that is designed to run over a LAN, so internet
> connection for the server is not really essential. Some users may
> deliberately not connect it to the internet as a security precaution.
>
> But I'd like the app to make use of an internet connection if it exists to
> check for an update, and notify the user.
>
> Is there a simple way for a PHP script to check if it has an internet
> connection?

If it's running on Linux, this will work. For other OS'es, you
may have to tweak it a bit.

<?php
$ip = '24.254.254.1'; // This is a bogus address. Replace it with yours.
exec('ping -c 1 -w 3 '.$ip,$ret,$err);
if($err) die('Internet connection unavailable.');
?>

This executes a system call to the PING utility, which then sends
a single packet with a deadline of 3 seconds to the address. If it
causes anything but a 0 return on STDERR, it dies with the message
"Internet connection unavailable."

Don't use name-based lookups unless you absolutely have to in this
case. There are more points of failure and bottlenecking, which can
make your code run really slow or fail completely.

--
</Daniel P. Brown>
daniel.brown(a)parasane.net || danbrown(a)php.net
http://www.parasane.net/ || http://www.pilotpig.net/
Looking for hosting or dedicated servers? Ask me how we can fit your budget!
From: Andy Shellam on
>
> Both at home and at work there are caching DNS on the LAN. So a DNS
> request may come back with a valid IP address when the WAN connection is
> down. I still won't be able to connect to the remote site.

Dig an external server - e.g. dig @a.root-servers.net google.co.uk

If your net is down the query will fail even if the reply is cached locally, because you're specifically requesting a response from a.root-servers.net.
From: Stuart Dallas on

On 21 Dec 2009, at 19:40, Andy Shellam wrote:

>>
>> Both at home and at work there are caching DNS on the LAN. So a DNS
>> request may come back with a valid IP address when the WAN connection is
>> down. I still won't be able to connect to the remote site.
>
> Dig an external server - e.g. dig @a.root-servers.net google.co.uk
>
> If your net is down the query will fail even if the reply is cached locally, because you're specifically requesting a response from a.root-servers.net.

I'm confused... what's the problem with just trying to hit the update server? If you can then you check for updates, if not then you, erm, don't. Simples, no?

-Stuart

--
http://stut.net/
From: "Bob McConnell" on
From: Andy Shellam

>>
>> Both at home and at work there are caching DNS on the LAN. So a DNS
>> request may come back with a valid IP address when the WAN connection
is
>> down. I still won't be able to connect to the remote site.
>
> Dig an external server - e.g. dig @a.root-servers.net google.co.uk
>
> If your net is down the query will fail even if the reply is
> cached locally, because you're specifically requesting a response
> from a.root-servers.net.

What means dig? I can't find it in the function index of the online
manual.

Bob McConnell
From: Ashley Sheridan on
On Tue, 2009-12-22 at 08:27 -0500, Bob McConnell wrote:

> From: Andy Shellam
>
> >>
> >> Both at home and at work there are caching DNS on the LAN. So a DNS
> >> request may come back with a valid IP address when the WAN connection
> is
> >> down. I still won't be able to connect to the remote site.
> >
> > Dig an external server - e.g. dig @a.root-servers.net google.co.uk
> >
> > If your net is down the query will fail even if the reply is
> > cached locally, because you're specifically requesting a response
> > from a.root-servers.net.
>
> What means dig? I can't find it in the function index of the online
> manual.
>
> Bob McConnell
>


It's not a PHP thing, it's a network thing (Domain Information Groper)

http://en.wikipedia.org/wiki/Domain_Information_Groper


Thanks,
Ash
http://www.ashleysheridan.co.uk


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5
Prev: Class "COM" not found
Next: SQL Queries