![]() |
Here is simple solution to check site is down or not. |
Example:
PHP
<?php
function isWebsiteUp($url) {
$ch = curl_init($url); // Initialize cURL session with the target URL
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // Set a timeout for the cURL operation (10 seconds)
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); // Set a timeout for the connection phase (10 seconds)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the transfer as a string instead of outputting it directly
curl_setopt($ch, CURLOPT_NOBODY, true); // Set to true to exclude the response body in the output
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Follow any redirects
curl_exec($ch); // Execute the cURL session
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // Get the HTTP status code
curl_close($ch); // Close the cURL session
// Check if the HTTP status code indicates success (200 range)
if ($httpcode >= 200 && $httpcode < 300) {
return true; // Website is likely up
} else {
return false; // Website is likely down or inaccessible
}
}
// Example usage:
$website_url = "https://www.google.com"; // Replace with the website you want to check
if (isWebsiteUp($website_url)) {
echo "$website_url is UP.";
} else {
echo "$website_url is DOWN or inaccessible.";
}
?>
php website access |
How to get country details from ip address using PHP | PHP Network Tutorial |
How to check if website is down or not in PHP | PHP Network Tutorial |
Type: | Develop |
Category: | Web Tutorial |
Sub Category: | PHP Network Tutorial |
Uploaded by: | Admin |