Re: Checking for internet connection.

From: Date: Sun, 20 Dec 2009 09:32:18 +0000
Subject: Re: Checking for internet connection.
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-300598@lists.php.net to get a copy of this message
> > 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.)

« previous php.general (#300598) next »