16c06-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 48 行
PHP
48 行
<?php// This program will run 'forever' checking the status of a provided webpage// Prepare by setting a timezone, mail() uses this.date_default_timezone_set('America/New_York');// Ensure that the email, URL, and seconds were provided:if ($argc < 4) { exit("Proper Usage: {$_SERVER['PHP_SELF']} <email> <url> <frequency>");}// We have the right number of parameters, let's assume they are correct:$email = $argv[1];$url = $argv[2];$seconds = $argv[3];// Make sure that we don't timeout:set_time_limit(0);// We need to do an initial grab of the URL:$saved = @file_get_contents($url);// Now, loop forever:while (true) { // Sleep for X seconds before trying to access the page again: sleep($seconds); // Ok, get a new copy of the page: $new = @file_get_contents($url); // Compare them to see if there is any difference: if ($saved !== $new) { // The page changed! First of all, save the 'new' as the 'saved' $saved = $new; // Now time to send that email! mail($email, "Page Changed - {$url}", "The URL that I was told to watch:{$url}Appears to have changed. I thought you might want to know that.Your friend,Automatic URL Watcher Robot", "From: {$email}"); }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?