forked from odolbeau/watch-url
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alexandresalome
committed
Jan 10, 2012
1 parent
ea28c96
commit c5c7fd4
Showing
3 changed files
with
47 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cache | ||
vendor | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"require": { | ||
"symfony/browser-kit": "2.1.0-dev" | ||
"kriswallsmith/buzz": "master-dev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
require_once __DIR__.'/vendor/.composer/autoload.php'; | ||
|
||
$dataDir = __DIR__.'/cache'; | ||
|
||
if (!is_dir($dataDir)) { | ||
mkdir($dataDir); | ||
} | ||
|
||
if (!isset($argv[1])) { | ||
echo "Usage: php read-title.php mon-url\n"; | ||
exit; | ||
} | ||
|
||
$url = $argv[1]; | ||
$hash = md5($url); | ||
|
||
$file = $dataDir.'/'.md5($hash); | ||
|
||
if (file_exists($file)) { | ||
list($statusCode, $content) = unserialize(file_get_contents($file)); | ||
} else { | ||
$statusCode = $content = null; | ||
} | ||
|
||
$browser = new Buzz\Browser(); | ||
|
||
$browser->call($url, 'GET'); | ||
$response = $browser->getLastResponse(); | ||
|
||
$newStatusCode = $response->getStatusCode(); | ||
$newContent = $response->getContent(); | ||
|
||
if ($statusCode !== null && $content !== null) { | ||
if ($newStatusCode != $statusCode || $newContent != $content) { | ||
echo 'The page has changed !'."\n"; | ||
echo 'Old status code: '.$statusCode."\n"; | ||
echo 'New status code: '.$newStatusCode."\n"; | ||
echo '------'."\n"; | ||
echo $newContent; | ||
exec("notify-send 'FREE!!! FREE!!! FREE!!! FREE!!! FREE!!! FREE!!! FREE!!! FREE!!! FREE!!! FREE!!!'"); | ||
} | ||
} | ||
|
||
file_put_contents($file, serialize(array($newStatusCode, $newContent))); |