Download the PHP package 1monitor/sdk-php without Composer

On this page you can find all versions of the php package 1monitor/sdk-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sdk-php

1Monitor SDK for PHP

CI Packagist PHP

Official PHP SDK for 1Monitor — ping your cron jobs, queue workers and scheduled tasks so you find out when they stop running.

Sending a ping never throws and never blocks for long. Monitoring must not be the thing that takes your job down. See The no-throw guarantee.

Requirements

PHP 8.1 or newer.

Install

Quickstart

Create a monitor in 1Monitor, copy its ping token, and call the SDK from the job you want watched.

That single call is enough for a heartbeat monitor: 1Monitor alerts you when the pings stop arriving.

Measuring how long a run takes

If you also want to know that a job finished, and how long it took, wrap the work in a start/finish pair. 1Monitor pairs them into a run, records its duration, and can alert on runs that fail or overrun.

Put the pingFail before the rethrow, not in a finally, so a crash still closes the run — and so the exception keeps propagating exactly as it would without the SDK.

Saying why it failed

ping, pingSuccess and pingFail optionally carry the job's exit code and output, so the alert can tell you what went wrong instead of just that something did:

The exit code travels as ?exit_code=N; a non-zero value marks the ping as failed even on a bare ping(). The output travels as the request body and is capped at 10 KB (Client::MAX_OUTPUT_BYTES) — the SDK truncates longer output before sending, because that is all the server would keep anyway.

1Monitor sweeps common credential shapes (tokens, API keys, private keys) out of ping output before storing it, but that is a safety net, not permission: send your job's diagnostic output, not its environment or its config.

Tagging pings with the deployed version

Every ping can carry the version of the code that sent it — a release number or the deployed commit SHA — so 1Monitor can tell which deploy a run belongs to. Pass it per call:

or once, on the client, so every ping carries it without touching the call sites:

A version passed to a call overrides the client's. It travels as ?version=…, after the exit code if there is one.

The version is trimmed and must then be 1–64 printable ASCII characters without whitespace — a SemVer string or a full 40-character SHA both fit. Anything else is dropped rather than thrown, the same way the server would drop it: the ping goes out without it (or with the client's version, when a call's own is the one dropped), and the SDK logs the dropped value at debug level. An empty or blank version means none and is not logged.

From a cron job

The same pattern as a standalone script, wired into your crontab:

Keep the token in the environment rather than in the source — it is a credential: anyone holding it can ping your monitor.

The four calls

Method URL Meaning
ping($token, ?$exitCode, ?$output, ?$version) /ping/{token} The job is alive.
pingStart($token, ?$version) /ping/{token}/start A run has started.
pingSuccess($token, ?$exitCode, ?$output, ?$version) /ping/{token}/success The open run finished successfully.
pingFail($token, ?$exitCode, ?$output, ?$version) /ping/{token}/fail The open run failed.

Each returns bool: true when 1Monitor accepted the ping, false when it did not.

exitCode, output and version are optional and named. A ping with output is sent as a POST with the output as the body; without one it stays a GET. pingStart carries no exit code or output — the job has not produced a result yet — but does carry a version. Exit codes outside 0–255 are ignored by the server.

Options

Every constructor option is optional and named:

Option Type Default What it does
baseUrl string https://ping.1monitor.io Where pings are sent. An http/https URL with an optional path prefix; credentials, a query string or a fragment are rejected.
timeout float 5.0 Seconds of network time shared across all attempts — see below.
retries int 2 Extra attempts after the first one fails. 0 disables retrying.
logger ?Psr\Log\LoggerInterface none Where failed pings are reported. Without one, failures are silent.
httpClient ?Psr\Http\Client\ClientInterface a plain Guzzle client Any PSR-18 client — for a proxy, custom TLS, or a different HTTP stack. A Guzzle client gets extra care — see below.
requestFactory ?Psr\Http\Message\RequestFactoryInterface guzzlehttp/psr7 Builds the ping requests (PSR-17).
streamFactory ?Psr\Http\Message\StreamFactoryInterface guzzlehttp/psr7 Builds the output body streams (PSR-17).
version ?string none Sent with every ping that does not pass its own — see Tagging pings with the deployed version. An invalid value is dropped and logged at debug, never thrown.

Maximum time a ping can hold up your job: timeout + backoff sleeps — about 6.5 s with the defaults (5 s of network time, plus 0.5 s and 1 s between the three attempts).

Why timeout is a budget, not a per-attempt limit

timeout is an overall deadline for time spent on the wire. Attempts draw it down as they run, and no retry starts once the budget is gone.

That is deliberate. If timeout only limited single attempts, three attempts against a hanging endpoint would block for 3 × 5 s plus backoff — around 16.5 s of your job's runtime spent on monitoring. The shared budget keeps the worst case flat no matter how many retries you allow.

Guzzle clients vs. other PSR-18 clients

The SDK drives a Guzzle client — the default, or any injected one — through Guzzle's own request API rather than its PSR-18 adapter, because the adapter supports neither per-request timeouts nor redirects. With Guzzle you therefore get the full guarantees: each attempt's socket timeout is the remaining budget (so the 6.5 s worst case above holds), and redirects are followed.

Guzzle receives these as per-request options, so they take precedence over whatever the injected client was configured with. A Guzzle client follows at most 5 redirects per attempt and, when baseUrl is https, refuses a redirect to http so the token is never sent in clear text.

With a non-Guzzle PSR-18 client, two things are yours to handle:

What gets retried

Only connection failures and 5xx responses. A 4xx is a decision, not a hiccup — a wrong token stays wrong, and a 429 means you are already sending too much — so those fail immediately. Backoff is roughly 0.5 s, then 1 s.

Ping constraints

If a monitor requires a specific HTTP method or header, inject an HTTP client configured with them — any PSR-18 client works, Guzzle shown here:

First-class options for this may be added later.

The no-throw guarantee

The SDK exists to tell you when a job stopped working. It must never be the reason a job stops working.

So delivering a ping never throws. A DNS failure, a dead network, a TLS error, an unreachable 1Monitor, a 404 from a deleted monitor, a 429, a 500 — all of them return false. Nothing propagates into your job.

Failures are reported to the PSR-3 logger you pass in, at error level. The context carries:

Key Value
state ping, start, success or fail
baseUrl The configured base URL
attempts How many attempts were made
status The last HTTP status, or null on a transport failure
error The class of the last exception, or null
reason Its message, or null

The ping token is a credential and is deliberately kept out of the log: the exception object itself is not passed on, because HTTP clients embed the request URL in it, and the token is redacted from the message. Without a logger, failures are dropped silently.

The only exceptions the SDK throws are your own mistakes, caught early and loudly:

Thrown When
OneMonitor\Sdk\Exception\InvalidArgumentException Malformed baseUrl, non-positive timeout, or negative retries — at construction.
OneMonitor\Sdk\Exception\InvalidArgumentException Empty ping token — at the call.

Both implement OneMonitor\Sdk\Exception\Exception, so catch (OneMonitor\Sdk\Exception\Exception $e) catches everything this package throws.

Testing code that pings

Client is final. Type-hint against OneMonitor\Sdk\ClientInterface instead and substitute a test double in your own tests:

The interface declares the same four methods as Client.

Security

Versioning

This package is at 0.x, and Composer treats 0.x minors as breaking. Require it as:

The version is deliberately below 1.0.0: the SDK's stability promise cannot exceed that of the ping API it wraps, which is not yet formally versioned. 1.0.0 follows once it is.

Changes are recorded in CHANGELOG.md.

Scope

Ping only. Management operations — creating, listing or pausing monitors, reading alerts — are not covered; there is no public management API yet. They will be added to this same package when there is, which is why it is named sdk-php and not ping-client.

Contributing

Bug reports and feature requests are welcome in GitHub Issues. Security issues follow a separate process — see SECURITY.md.

See CONTRIBUTING.md for the development setup, the checks CI runs, and the design constraints a change must respect.

License

MIT — see LICENSE.


All versions of sdk-php with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
guzzlehttp/guzzle Version ^7.0 || ^8.0
guzzlehttp/psr7 Version ^2.6 || ^3.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/http-message Version ^1.1 || ^2.0
psr/log Version ^1.1 || ^2.0 || ^3.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package 1monitor/sdk-php contains the following files

Loading the files please wait ...