Is there a quicker and more efficient way to check if a website shows status codes 200 etc?
Basically I want to check specific pages whether they're online of offline. Some of the pages I check go down sporadically with 502 errors, so I need a way to also make sure those are displayed as "offline" thus using the header response check.
when using the below function on say 5-10 pages, it slows the page loading time dramatically.
<?php
function getHttpResponseCode( string $url ) //: int
{
$headers = get_headers( $url );
return substr( $headers[ 0 ], 9, 3 );
}
if (getHttpResponseCode('https://www.google.com') !='200') {
echo 'offline';
} else {
echo 'online';
}
?>
**UPDATED CODE (not working atm) **
<?php
function checkDomain($host) {
if($socket =@ fsockopen($host, 80, $errno, $errstr, 30)) {
echo 'online!';
fclose($socket);
} else {
echo 'offline.';
}
}
echo checkDomain('https://www.google.com');
?>