Created
July 12, 2016 17:02
-
-
Save fotan/911f58ca45050e408ce34f6383303d2f to your computer and use it in GitHub Desktop.
PHP - Check server code on a URL (See if website is up)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$url = “http://fotan.us”; | |
$handle = curl_init($url); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE); | |
/* Get the HTML or whatever is linked in $url. */ | |
$response = curl_exec($handle); | |
/* Check the return code. */ | |
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
/* | |
Common return codes | |
200 - OK | |
301 - Moved Permanently | |
302 - Moved Temporarily | |
400 - Bad request | |
401 - Unauthorized | |
403 - Forbidden | |
404 - Not Found | |
406 - Not Accepted | |
408 - Request Time-out | |
500 - Server Error | |
502 - Bad Gateway | |
503 - Out of Resources | |
504 - Gateway Time-Out | |
*/ | |
// Do something with the result | |
if($httpCode == 200) { | |
echo “Everything is OK”; | |
} | |
curl_close($handle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment