Monitoring Website using PHP file_get_contents and mail function

Categories: PHP; Tagged with: ; @ May 13th, 2014 22:20

As a lazy user, I want to get alerted when website goes down.

Solution:

	$homepage = file_get_contents('http://,monitoring--domain.com/');
        if(strlen($homepage) > 0) {
                echo "Got response, no action";
        }else {
                echo "No response from server, send out email...";
                $to      = '[email protected]';
                $subject = 'Weak up, you website is down!';
                $message = 'Weak up, you website is down!';
                $headers = 'From: [email protected]' . "\r\n" .
                'Reply-To: [email protected]' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
                mail($to, $subject, $message, $headers);
        }

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.