How can I check if I'm connected to the internet from my PHP script which is running on my dev machine?
I run the script to download a set of files (which may or may not exist) using wget. If I try the download without being connected, wget proceeds to the next one thinking the file is not present.
This code was failing in laravel 4.2 php framework with an internal server 500 error:
Which I didn't want to stress myself to figure that out, hence I tried this code and it worked for me:
Please note that: This is based upon the assumption that the connection to google.com is less prone to failure.
This function handles what you need
Why don't you fetch the return code from wget to determine whether or not the download was successful? The list of possible values can be found at wget exit status.
On the other hand, you could use php's curl functions as well, then you can do all error tracking from within PHP.