Search by

zaengle / craft-phonehome

jesseschutttomdavies

Phone Home plugin for Craft CMS

Package info

github.com/zaengle/craft-phonehome

Type:craft-plugin

pkg:composer/zaengle/craft-phonehome

Statistics

Installs: 8 542

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 20


README

Monitor the status of your #CraftCMS projects remotely

Phonehome a secure API endpoint that returns comprehensive information about a Craft CMS installation and the server environment it is installed in.

Requirements

This plugin requires Craft CMS 4.0.0+ or 5.0.0+, and PHP 8.1+.

Quickstart Installation

composer require zaengle/craft-phonehome
./craft plugin/install phonehome

then in config/phonehome.php add:

return [
     // Your secure token from the Zaengle Phone Home service. Keep the single quotes: the value is
     // the name of the environment variable, which the plugin resolves when it checks a request.
     'token' => '$PHONEHOME_TOKEN',
];

Use a random token of at least 32 characters, for example the output of openssl rand -hex 32. A shorter token is refused, and the site rejects every request until the token is replaced.

The plugin's settings page also accepts the token, but only as an environment variable reference such as $PHONEHOME_TOKEN, so that the token is kept out of project config.

Documentation

See the full documentation in the docs/ directory of this repository.

What the API Reports

By default, the API returns only the fields the Phone Home dashboard uses: the PHP, Craft and database versions, the operating system, plugins, modules, available updates, npm dependencies, status checks, the deployed revision and the verification manifest. A site can opt in to the full report, which adds the meta section and the rest of system, by setting fullReport in config/phonehome.php. The full report is meant as a troubleshooting aid, and it can only be turned on from the config file:

return [
    'token' => '$PHONEHOME_TOKEN',
    'fullReport' => true,
];

See the API documentation for the exact fields in each report.

API Schema

The plugin provides a JSON schema that defines the structure of the API response. The schema is located at src/schemas/PhonehomeApi.schema.json and follows semantic versioning.

You can retrieve the schema via the API endpoint:

GET /actions/phonehome/api/schema
X-Auth-Token: your-token-here

Important for contributors: When modifying the API response structure in Report::getInfo(), you must update the schema file accordingly and bump the schema version following semantic versioning rules. See CLAUDE.md for detailed schema maintenance guidelines.

Configuration

Additional Environment Variables

When the full report is turned on, you can include additional environment variables in the API response by setting additionalEnvKeys in your config/phonehome.php. This setting is read only from the config file, never from the control panel:

return [
    'token' => '$PHONEHOME_TOKEN',
    'fullReport' => true,
    'additionalEnvKeys' => [
        'MY_CUSTOM_ENV_VAR',
        'DEPLOYMENT_ID',
        'BUILD_NUMBER',
    ],
];

These values are included in the meta section of the API response. Only the full report carries meta, so this setting has no effect unless fullReport is also true. A value whose name looks sensitive is masked, and credentials are stripped from URL values.

Extensibility

Custom Status Checks

You can register custom status checks to monitor application-specific health metrics. Status checks are registered via Craft's event system:

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;
    }
);

Your status check class must implement StatusCheckInterface:

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',
            ],
        ]);
    }
}

Support

For support, visit the GitHub repository.

Development

See the development guide for details on how to contribute to this project.