cronbeats/cronbeats-php
Composer 安装命令:
composer require cronbeats/cronbeats-php
包简介
Cron job monitoring and heartbeat monitoring SDK for PHP. Monitor scheduled tasks, background jobs, and cron jobs with simple ping telemetry. Get alerts when cron jobs fail, miss their schedule, or run too long.
关键字:
README 文档
README
Official PHP SDK for CronBeats ping telemetry.
Install
composer require cronbeats/cronbeats-php
Quick Start
<?php require __DIR__ . '/vendor/autoload.php'; use CronBeats\PingSdk\PingClient; $client = new PingClient('abc123de', [ 'baseUrl' => 'https://cronbeats.io', 'timeoutMs' => 5000, 'maxRetries' => 2, ]); // Simple heartbeat $client->ping(); // Start/end signals $client->start(); // ... do work ... $client->success();
Real-World Cron Job Example
<?php $client = new PingClient('abc123de'); $client->start(); try { // your actual cron work processEmails(); $client->success(); } catch (Exception $e) { $client->fail(); }
Progress Tracking
Track your job's progress in real-time. CronBeats supports two distinct modes:
Mode 1: With Percentage (0-100)
Shows a progress bar and your status message on the dashboard.
✓ Use when: You can calculate meaningful progress (e.g., processed 750 of 1000 records)
<?php // Percentage mode: 0-100 with message $client->progress(50, 'Processing batch 500/1000'); // Or using options array $client->progress([ 'seq' => 75, 'message' => 'Almost done - 750/1000', ]);
Mode 2: Message Only
Shows only your status message (no percentage bar) on the dashboard.
✓ Use when: Progress isn't measurable or you only want to send status updates
<?php // Message-only mode: null seq, just status updates $client->progress(null, 'Connecting to database...'); $client->progress(null, 'Starting data sync...');
What you see on the dashboard
- Mode 1: Progress bar (0-100%) + your message → "75% - Processing batch 750/1000"
- Mode 2: Only your status message → "Connecting to database..."
Complete Example
<?php $client = new PingClient('abc123de'); $client->start(); try { // Message-only updates for non-measurable steps $client->progress(null, 'Connecting to database...'); $db = connectToDatabase(); $client->progress(null, 'Fetching records...'); $total = $db->count(); // Percentage updates for measurable progress for ($i = 0; $i < $total; $i++) { processRecord($i); if ($i % 100 === 0) { $percent = (int)($i * 100 / $total); $client->progress($percent, "Processed $i / $total records"); } } $client->progress(100, 'All records processed'); $client->success(); } catch (Exception $e) { $client->fail(); throw $e; }
Error Handling
<?php use CronBeats\PingSdk\Exception\ApiException; use CronBeats\PingSdk\Exception\ValidationException; try { $client->ping(); } catch (ValidationException $e) { // Invalid local inputs like malformed job key } catch (ApiException $e) { // API/network issue with normalized metadata $code = $e->getErrorCode(); // e.g. RATE_LIMITED $status = $e->getHttpStatus(); // e.g. 429 }
API Surface
ping()start()end('success'|'fail')success()fail()progress(int|array|null $seqOrOptions, ?string $message = null)
Notes
- SDK uses
POSTfor telemetry requests. jobKeymust be exactly 8 Base62 characters.- Retries happen only for network errors, HTTP
429, and HTTP5xx. - Default 5s timeout ensures the SDK never blocks your cron job if CronBeats is unreachable.
cronbeats/cronbeats-php 适用场景与选型建议
cronbeats/cronbeats-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cron」 「monitoring」 「background jobs」 「ping」 「scheduler」 「devops」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cronbeats/cronbeats-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cronbeats/cronbeats-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cronbeats/cronbeats-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
Provides a background task processing module.
A Symfony bundle for chameleon-system/sanitycheck
SoftWax Health Check Bundle for Symfony framework
Scheduling extension for Yii2 framework
1Pilot client for Symfony
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 40
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-25