Re: Checking for internet connection.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Dec 20, 2009 at 2:32 AM, Andy Shellam <andy-lists@xxxxxxxxxxxxxx> wrote:
>>
>> I think the only way to detect if it can connect to the Internet is to
>> see if you can grab a file from somewhere on the Internet. I'd hazard a
>> guess that when operating systems are able to tell you they can "connect
>> to the Internet" they are actually saying they can ping a predetermined
>> remote host. I think checking if PHP can grab a remote file with Curl
>> would be sufficient in this case.
>
> Personally, I'd do a DNS lookup - even connecting to a server is a lot more overhead than a simple DNS request.  You could force the DNS server to be one external to your network - e.g. dig @a.root-servers.net www.google.co.uk.  If the dig command fails, you're not connected.
>
> Or just try and get the update anyway - if the download fails, you're not connected (or there's something wrong with the update server.)

By attempting to connect you will implicitly query DNS (which itself
is a connection to server).  If you're not online you won't be able to
resolve the domain name.  Hence no overhead of actually connecting,
because that won't even start to happen until the hostname is resolved
to an IP.  If it happens to resolve from some cache, oh well.  Not
like its that much overhead.  You're nitpicking over the number of
packets it takes to SYN/ACK.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux