dev-master
9999999-dev
GPL-3.0
The Requires
The Development Requires
Wallogit.com
2017 © Pedro Peláez
This library should help to provide information about uptimes of network services with PHP., (*1)
There are different kind of checks implemented., (*2)
This checks requests a given HTTP(S) resource and checks it for a list of keywords. Since it checks the plain any return value can be checked., (*3)
use Phizzl\UptimeTools\Checks\CheckFactory;
$checkFactory = new CheckFactory();
$check = $checkFactory->create(CheckFactory::TYPE_HTTPKEYWORDS, [
'host' => 'https://www.heise.de',
'keywords' => ['heise online Themen', 'heise Security', '</html>']
]);
Ping check is sending one ping to a given host., (*4)
use Phizzl\UptimeTools\Checks\CheckFactory;
$checkFactory = new CheckFactory();
$check = $checkFactory->create(CheckFactory::TYPE_PING, [
'host' => 'www.gitub.com'
]);
You may check wether a given TCP port is open on a defined host or not., (*5)
use Phizzl\UptimeTools\Checks\CheckFactory;
$checkFactory = new CheckFactory();
$check = $checkFactory->create(CheckFactory::TYPE_TCP, [
'host' => 'www.github.com',
'port' => 80
]);
To execute the checks they need to added to a bucket. A bucket can euqal your application. For example a Webserver. You may want to test if it's pingable, the TCP port 80 is open and you find the closing HTML tag on your index., (*6)
use Phizzl\UptimeTools\Buckets\Bucket;
use Phizzl\UptimeTools\Buckets\DispatchedBucket;
use Phizzl\UptimeTools\Checks\CheckFactory;
use Phizzl\UptimeTools\Checks\DispatchedCheck;
$bucket = new Bucket();
$checkFactory = new CheckFactory();
$bucket->getChecks()->addCheck($checkFactory->create(CheckFactory::TYPE_TCP, [
'host' => 'www.mywebsite.local',
'port' => 80
]));
$bucket->getChecks()->addCheck($checkFactory->create(CheckFactory::TYPE_HTTPKEYWORDS, [
'host' => 'http://www.mywebsite.local',
'keywords' => ['</html>']
]));
$bucket->getChecks()->addCheck($checkFactory->create(CheckFactory::TYPE_PING, [
'host' => 'www.mywebsite.local'
]));
$dispatchedBucket = $bucket->run();
echo "Checks took {$dispatchedBucket->getDispatchTime()}s\n";
echo "--------------------------------------\n";
/* @var DispatchedCheck $dispatchedCheck */
foreach($dispatchedBucket->getSucceededDispatchedChecks() as $dispatchedCheck){
echo "Success: " . get_class($dispatchedCheck->getContext()->getCheck()) . PHP_EOL;
echo "Executed in: {$dispatchedCheck->getDispatchTime()}s\n";
echo "--------------------------------------\n";
}
/* @var DispatchedCheck $dispatchedCheck */
foreach($dispatchedBucket->getFailedDispatchedChecks() as $dispatchedCheck){
echo "Failed: " . get_class($dispatchedCheck->getContext()->getCheck()) . PHP_EOL;
echo "Executed in: {$dispatchedCheck->getDispatchTime()}s\n";
echo "Message: {$dispatchedCheck->getMessage()}\n";
echo "--------------------------------------\n";
}
if($dispatchedBucket->getStatus() === DispatchedBucket::STATUS_SUCCESS){
echo "All checks passed!\n";
exit(0);
}
else{
echo "Error occured!\n";
exit(1);
}
GPL-3.0