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      = 'test@test.com';
                $subject = 'Weak up, you website is down!';
                $message = 'Weak up, you website is down!';
                $headers = 'From: webmaster@example.com' . "\r\n" .
                'Reply-To: webmaster@example.com' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
                mail($to, $subject, $message, $headers);
        }

<->



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