PHP code example of crontinel / php

1. Go to this page and download the library: Download crontinel/php 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/ */

    

crontinel / php example snippets


$client = new \Crontinel\Client('your_api_key');
$client->baseUrl('https://app.crontinel.com/api/v1');

// Report a cron run
$client->reportCronRun('php artisan schedule:run', 1500, 0);

use Crontinel\Contracts\MonitorInterface;

final class DiskSpaceMonitor implements MonitorInterface
{
    public function __construct(
        private readonly string $path = '/',
        private readonly float $minFreePercent = 10.0,
    ) {}

    public function isHealthy(): bool
    {
        $free = disk_free_space($this->path);
        $total = disk_total_space($this->path);

        return ($free / $total) * 100 >= $this->minFreePercent;
    }
}

use Crontinel\Contracts\AlertChannelInterface;
use Crontinel\Data\AlertEvent;

final class WebhookChannel implements AlertChannelInterface
{
    public function __construct(
        private readonly string $url,
    ) {}

    public function send(AlertEvent $event): void
    {
        file_get_contents($this->url, false, stream_context_create([
            'http' => [
                'method' => 'POST',
                'header' => 'Content-Type: application/json',
                'content' => json_encode([
                    'key'      => $event->key,
                    'title'    => $event->title,
                    'message'  => $event->message,
                    'level'    => $event->level,
                    'resolved' => $event->resolved,
                ]),
            ],
        ]));
    }
}

use Crontinel\Alert\AlertManager;

// Requires any PSR-16 cache implementation
$alertManager = new AlertManager(
    cache: $cache,
    channel: new WebhookChannel('https://example.com/webhook'),
);

$monitor = new DiskSpaceMonitor('/data');

if (! $monitor->isHealthy()) {
    $alertManager->fire('disk.data', 'Low disk space', 'Disk /data is below 10% free', 'critical');
} else {
    $alertManager->resolve('disk.data');
}

use Crontinel\Cron\CronExpressionHelper;

$helper = new CronExpressionHelper();

// When is the next run of "every minute"?
$next = $helper->nextDue('* * * * *');
echo $next->format('Y-m-d H:i:s');

// Is a job that's been silent for 10 minutes late for a 5-minute schedule?
$lastRun = new \DateTimeImmutable('2026-04-11 10:50:00');
$isLate = $helper->isLate($lastRun, '*/5 * * * *', graceSeconds: 60);
// Returns true if current time exceeds $lastRun + 5min + 60s grace

use Crontinel\Alert\AlertManager;
use Crontinel\Monitors\QueueMonitor;

$alertManager = new AlertManager(
    cache: $cache,
    channel: new WebhookChannel('https://example.com/alerts'),
);

$queueMonitor = new QueueMonitor(
    redisConnection: 'default',
    maxDepth: 100,
    maxFailed: 10,
);

if (! $queueMonitor->isHealthy()) {
    $status = $queueMonitor->getStatus(); // returns QueueStatus object
    $alertManager->fire(
        'queue.depth',
        'Queue depth exceeded',
        "Queue has {$status->depth} jobs (max: 100)",
        'warning',
    );
}
bash
composer 
bash
composer