Download the PHP package cleatsquad/php-error-boundary without Composer

On this page you can find all versions of the php package cleatsquad/php-error-boundary. 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 php-error-boundary

PHP Error Boundary

Tests codecov

A best-effort, last-resort JSON envelope for the PHP fatals and uncaught exceptions your framework's own error handling never gets a chance to see — not a replacement for it.

A fatal — a timeout, a memory limit, an autoload failure — is not a Throwable, so no try/catch reaches it, and that includes the try/catch a PSR-15 pipeline or a framework's own error middleware wraps around dispatch. Left unhandled, PHP writes an HTML error page into a response body the client expected as JSON. This library installs an exception handler and a shutdown handler that both answer with the same JSON contract, so that page never reaches the client.

"Best-effort" is deliberate, not modesty. register_shutdown_function() observes some fatals — memory_limit, max_execution_time, a parse error — because PHP still runs a termination phase for them. It observes nothing from a SIGKILL, an OOM-killed process, a segfault, or the infrastructure simply terminating the worker: PHP itself never resumes to run the shutdown function in those cases. This library answers what PHP's termination phase gives it a chance to answer — no library can promise more than that against a process that never comes back.

Installation

Requires PHP 8.2 or later. No runtime dependencies.

Usage

Install once, at the entry point

Every uncaught exception and every fatal error (E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR) now answers with a JSON body instead of an HTML one — a 504 for a timeout, a 500 for anything else.

Customise the mapping

Send the uncaught-exception line through your own logger

When a PSR-3 LoggerInterface is supplied, the uncaught-exception line goes through $logger->error() (the exception is passed as ['exception' => $e] context) instead of error_log(). Fatals caught by the shutdown handler are not logged here — PHP has already written them to the error log itself by the time it fires.

Uninstall

Restores PHP's default exception handler and makes the boundary inert for the shutdown handler already registered (PHP has no unregister_shutdown_function(), so it stays registered but becomes a no-op). Clears the mapper, logger and shutdown interceptor, so a later install() starts clean. Useful in tests, or when handing control back to another error-handling system for the rest of the process.

Intercept before the standard response is emitted

Useful for a response format the boundary doesn't own by default — an active Server-Sent Events stream, for instance, where the error must be framed as an event rather than a fresh HTTP response.

Examples

Full, runnable-style snippets for common setups live in examples/:

Design notes

No stack trace, no file path, ever reaches the client. The default mapper returns a fixed internal_error/upstream_timeout code and a generic message — never $error['message'] verbatim, which could leak an internal path or class name.

Fail-open by design. If headers_sent() is already true, emit() does nothing rather than corrupt a response that may already be partially written.

One static boundary per process. The handler is process-global by construction — that's what lets it catch a fatal PHP itself doesn't let you catch. Call install() once, at the entry point.

Limits

This is not a PSR-15 middleware, and it cannot be one. PSR-15 (MiddlewareInterface) relies on the call stack staying alive — a try/catch around $handler->handle($request) — to intercept an error. A PHP fatal (E_ERROR, a memory_limit exhaustion, a max_execution_time timeout) is not a Throwable: no try/catch anywhere, PSR-15 pipeline included, ever sees it. PHP terminates execution immediately, and the call stack — the pipeline itself — is gone with it. The only hook PHP leaves after that is register_shutdown_function(), a process-global termination phase with no pipeline left to resume. That's a constraint of the language, not a design choice: no amount of engineering turns "catch a fatal" into a composable middleware object.

Concretely:

Testing

License

MIT. See LICENSE.


All versions of php-error-boundary with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
psr/log Version ^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 cleatsquad/php-error-boundary contains the following files

Loading the files please wait ...