PHPackages                             nathanielks/cronitor-io-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. nathanielks/cronitor-io-php

ActiveLibrary[API Development](/categories/api)

nathanielks/cronitor-io-php
===========================

Cronitor PHP Library

1.3.2(2y ago)3138.2k14MITPHPPHP &gt;=5.6CI failing

Since Feb 5Pushed 10mo ago1 watchersCompare

[ Source](https://github.com/nathanielks/cronitor-io-php)[ Packagist](https://packagist.org/packages/nathanielks/cronitor-io-php)[ Docs](https://cronitor.io/)[ RSS](/packages/nathanielks-cronitor-io-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (4)Versions (41)Used By (0)

Cronitor PHP Library
====================

[](#cronitor-php-library)

[![Test](https://github.com/cronitorio/cronitor-php/workflows/Test/badge.svg)](https://github.com/cronitorio/cronitor-php/workflows/Test/badge.svg)

[Cronitor](https://cronitor.io/) provides end-to-end monitoring for background jobs, websites, APIs, and anything else that can send or receive an HTTP request. This library provides convenient access to the Cronitor API from applications written in PHP. See our [API docs](https://cronitor.io/docs/api) for detailed references on configuring monitors and sending telemetry pings.

In this guide:

- [Installation](#Installation)
- [Monitoring Background Jobs](#monitoring-background-jobs)
- [Sending Telemetry Events](#sending-telemetry-events)
- [Configuring Monitors](#configuring-monitors)
- [Package Configuration &amp; Env Vars](#package-configuration)

Installation
------------

[](#installation)

```
composer require cronitor/cronitor-php
```

To use manually, you can include the `init.php` file from source.

```
require_once('/path/to/cronitor-php/init.php');
```

### Monitoring Background Jobs

[](#monitoring-background-jobs)

The `$cronitor->job` function will send telemetry events before calling your function and after it exits. If your function raises an exception a `fail` event will be sent (and the exception re-raised).

```
$cronitor = new Cronitor\Client('api_key_123');

$closureVar = time();
$cronitor->job('weekly-report-job', function() use ($closureVar){
  new WeeklyReportJob($closureVar)->run();
});
```

Sending Telemetry Events
------------------------

[](#sending-telemetry-events)

If you want to send a heartbeat events, or want finer control over when/how [telemetry events](https://cronitor.io/docs/telemetry-api) are sent for your jobs, you can create a `Monitor` instance and call the `.ping` method.

```
$cronitor = new Cronitor\Client('api_key_123');

$monitor = $cronitor->monitor('heartbeat-monitor');

$monitor->ping(); # a basic heartbeat event

# optional params can be passed as kwargs
# complete list - https://cronitor.io/docs/telemetry-api#parameters

$monitor->ping(['state' => 'run']); # a job/process has started

# a job/process has completed (include metrics for Cronitor to record)
$monitor->ping(['state' => 'complete', 'metrics' => ['count' => 1000, 'error_count' => 17]]);
```

Configuring Monitors
--------------------

[](#configuring-monitors)

### Yaml Configuration File

[](#yaml-configuration-file)

You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of a deployment or build process. For details on all of the attributes that can be set, see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.

```
# read config file and set credentials (if included).
$cronitor->readConfig('./cronitor.yaml');

# sync config file's monitors to Cronitor.
$cronitor->applyConfig();

# send config file's monitors to Cronitor to validate correctness.
# monitors will not be saved.
$cronitor->validateConfig();

# save config to local YAML file (defaults to cronitor.yaml)
$cronitor->generateConfig();
```

The `cronitor.yaml` file includes three top level keys `jobs`, `checks`, `heartbeats`. You can configure monitors under each key by declaring a monitor `key` and defining [Monitor attributes](https://cronitor.io/docs/monitor-api#attributes)

```
jobs:
  nightly-database-backup:
    schedule: 0 0 * * *
    notify:
      - devops-alert-pagerduty
    assertions:
      - metric.duration < 5 minutes

  send-welcome-email:
    schedule: every 10 minutes
    assertions:
      - metric.count > 0
      - metric.duration < 30 seconds

checks:
  cronitor-homepage:
    request:
      url: https://cronitor.io
      regions:
        - us-east-1
        - eu-central-1
        - ap-northeast-1
    assertions:
      - response.code = 200
      - response.time < 2s

  cronitor-telemetry-api:
    request:
      url: https://cronitor.link/ping
    assertions:
      - response.body contains ok
      - response.time < .25s

heartbeats:
  production-deploy:
    notify:
      alerts: ["deploys-slack"]
      events: true # send alert when the event occurs
```

#### Async Uploads

[](#async-uploads)

If you are working with large YAML files (300+ monitors), you may hit timeouts when trying to sync monitors in a single http request. This workload to be processed asynchronously by adding the key `async: true` to the config file. The request will immediately return a `batch_key`. If a `webhook_url` parameter is included, Cronitor will POST to that URL with the results of the background processing and will include the `batch_key` matching the one returned in the initial response.

### $cronitor-&gt;monitors-&gt;put

[](#cronitor-monitors-put)

You can also create and update monitors by calling `$cronitor->monitors->put`. For details on all of the attributes that can be set see the Monitor API \[documentation)().

```
$cronitor->monitors->put([
  [
    'type' => 'job',
    'key' => 'send-customer-invoices',
    'schedule' => '0 0 * * *',
    'assertions' => [
        'metric.duration < 5 min'
    ],
    'notify' => ['devops-alerts-slack']
  ],
  [
    'type' => 'check',
    'key' => 'Cronitor Homepage',
    'schedule' => 'every 45 seconds',
    'request' => [
        'url' => 'https://cronitor.io'
    ]
    'assertions' => [
        'response.code = 200',
        'response.time < 1.5s',
        'response.json "open_orders" < 2000'
    ]
  ]
])
```

### Pause, Reset, Delete

[](#pause-reset-delete)

```
require 'cronitor'

$monitor = $cronitor->monitor('heartbeat-monitor');

$monitor->pause(24) # pause alerting for 24 hours
$monitor->unpause() # alias for ->pause(0)
$monitor->ok() # manually reset to a passing state alias for $monitor->ping({state: ok})
$monitor->delete() # destroy the monitor
```

Package Configuration
---------------------

[](#package-configuration)

The package needs to be configured with your account's `API key`, which is available on the [account settings](https://cronitor.io/settings) page. You can also optionally specify an `api_version` and an `environment`. If not provided, your account default is used. These can also be supplied using the environment variables `CRONITOR_API_KEY`, `CRONITOR_API_VERSION`, `CRONITOR_ENVIRONMENT`.

```
$apiKey = 'apiKey123';
$apiVersion = '2020-10-01';
$environment = 'staging';
$cronitor = new Cronitor\Client($apiKey, $apiVersion, $environment);
```

Contributing
------------

[](#contributing)

Pull requests and features are happily considered! By participating in this project you agree to abide by the [Code of Conduct](http://contributor-covenant.org/version/2/0).

### To contribute

[](#to-contribute)

Fork, then clone the repo:

```
git clone git@github.com:your-username/cronitor-php.git

```

Push to your fork and [submit a pull request](https://github.com/cronitorio/cronitor-php/compare/)

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~132 days

Recently: every ~229 days

Total

23

Last Release

830d ago

Major Versions

0.3.1 → 1.0.02021-02-25

PHP version history (3 changes)0.1.0PHP &gt;=5.4.0

1.0.0PHP &gt;=5.6.0

1.0.7PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c3788053d77088672a61954c754922855388f8c85de3623344abe92d34135df?d=identicon)[nathanielks](/maintainers/nathanielks)

---

Top Contributors

[![nathanielks](https://avatars.githubusercontent.com/u/314009?v=4)](https://github.com/nathanielks "nathanielks (79 commits)")[![aflanagan](https://avatars.githubusercontent.com/u/702589?v=4)](https://github.com/aflanagan "aflanagan (41 commits)")[![seanmcoleman](https://avatars.githubusercontent.com/u/186030?v=4)](https://github.com/seanmcoleman "seanmcoleman (33 commits)")[![dongm2ez](https://avatars.githubusercontent.com/u/9032795?v=4)](https://github.com/dongm2ez "dongm2ez (5 commits)")[![nauxliu](https://avatars.githubusercontent.com/u/9570112?v=4)](https://github.com/nauxliu "nauxliu (4 commits)")[![ChargemapFranck](https://avatars.githubusercontent.com/u/51370562?v=4)](https://github.com/ChargemapFranck "ChargemapFranck (2 commits)")[![zaherg](https://avatars.githubusercontent.com/u/27624?v=4)](https://github.com/zaherg "zaherg (1 commits)")[![effata](https://avatars.githubusercontent.com/u/204507?v=4)](https://github.com/effata "effata (1 commits)")[![pableu](https://avatars.githubusercontent.com/u/305859?v=4)](https://github.com/pableu "pableu (1 commits)")[![devnulls](https://avatars.githubusercontent.com/u/13037881?v=4)](https://github.com/devnulls "devnulls (1 commits)")

---

Tags

apicronitor

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/nathanielks-cronitor-io-php/health.svg)

```
[![Health](https://phpackages.com/badges/nathanielks-cronitor-io-php/health.svg)](https://phpackages.com/packages/nathanielks-cronitor-io-php)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[darkaonline/swagger-lume

OpenApi or Swagger integration to Lumen

3372.3M3](/packages/darkaonline-swagger-lume)[cronitor/cronitor-php

Cronitor PHP Library

31871.6k](/packages/cronitor-cronitor-php)[sleeping-owl/apist

Package to provide api-like access to foreign sites based on html parsing

3105.3k](/packages/sleeping-owl-apist)[adrenalinkin/swagger-resolver-bundle

Provides possibility for validate data according to Swagger documentation

1013.3k](/packages/adrenalinkin-swagger-resolver-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
