PHP code example of zaengle / craft-phonehome

1. Go to this page and download the library: Download zaengle/craft-phonehome library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zaengle / craft-phonehome example snippets


return [
     'token' => getenv('PHONEHOME_TOKEN'), // Your secure token from Zaengle Phone Home service
];

return [
    'token' => getenv('PHONEHOME_TOKEN'),
    'additionalEnvKeys' => [
        'MY_CUSTOM_ENV_VAR',
        'DEPLOYMENT_ID',
        'BUILD_NUMBER',
    ],
];

use yii\base\Event;
use zaengle\phonehome\services\Report;
use zaengle\phonehome\events\RegisterStatusChecksEvent;

Event::on(
    Report::class,
    Report::EVENT_REGISTER_STATUS_CHECKS,
    function(RegisterStatusChecksEvent $event) {
        $event->checks[] = MyCustomStatusCheck::class;
    }
);

use zaengle\phonehome\statuschecks\StatusCheckInterface;
use zaengle\phonehome\models\StatusCheckResult;
use zaengle\phonehome\enums\StatusCheck;

class MyCustomStatusCheck implements StatusCheckInterface
{
    public static function getName(): string
    {
        return 'My Custom Check';
    }

    public static function getDescription(): string
    {
        return 'Monitors custom application metrics';
    }

    public static function check(): StatusCheckResult
    {
        return new StatusCheckResult([
            'name' => self::getName(),
            'status' => StatusCheck::OK,
            'description' => self::getDescription(),
            'meta' => [
                'custom_metric' => 'value',
            ],
        ]);
    }
}