Global error handler
QuietGuard\Monitor\ErrorHandler registers PHP's global handlers so a plain-PHP host with no framework exception pipeline still reports uncaught errors. Frameworks (Laravel, Symfony) have their own hooks and should not call this.
Registering
ErrorHandler::register() is a single static call that takes a configured Reporter:
Call it once, as early as possible in your bootstrap, after the Reporter is built.
What it registers
register() wires three global hooks:
set_exception_handler, any uncaughtThrowableis sent via$reporter->reportException($e). The handler chains: if another global exception handler was registered beforeErrorHandler::register(), it still runs after the exception has been reported (the monitor reports first, then delegates). When no previous handler exists, the exception (message, file:line and stack trace) is written toerror_log, matching what PHP's default behavior would have recorded: installing monitoring never removes the host's local crash record.set_error_handler, a raised PHP error is wrapped in anErrorExceptionand reported, provided its severity is at or above the floor described below. It first checkserror_reporting() & $severity, so values suppressed with@or below the currenterror_reportinglevel are skipped. It then returnsfalseso PHP's normal error handling still runs.register_shutdown_function, on shutdown,error_get_last()is inspected and, if it is a fatal type (E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR), anErrorExceptionis reported. This catches fatals that the error handler cannot.
Every path runs through the Reporter, which never throws, so registering these handlers cannot break the host.
The severity floor, and the cap that goes with it
register() takes two optional arguments:
By default only E_USER_ERROR and E_RECOVERABLE_ERROR are reported. Every severity used to be forwarded, one synchronous POST each, with no floor, no de-duplication and no cap: a single E_WARNING inside a loop over five hundred rows was five hundred blocking HTTP calls in one page load, which reads to a visitor as an outage and burns a free plan's monthly events in a day.
The true fatals are absent from the default on purpose. PHP calls no user error handler for E_ERROR, E_PARSE, E_CORE_ERROR or E_COMPILE_ERROR, and the shutdown hook above is what catches those already. What the default keeps is the pair a host actually raises and means: a userland fatal, and a type error PHP let through.
Two guards apply whatever the mask:
- one report per site per request: the same error raised on the same
file:linea hundred times is one fact, and the other ninety-nine POSTs are the host application's latency, not yours to spend; - a cap of
$maxPerRequest, 20 by default, because a mask cannot see a loop: fifty distinct lines pass any floor and are still fifty requests.
Pass the mask explicitly to widen it, knowing what it costs:
A minimal plain-PHP bootstrap
The Laravel SDK and the Symfony bundle do not useErrorHandler: each hooks its framework's own exception pipeline. The WordPress plugin does use it, WordPress having no exception pipeline of its own, and takes the default floor. Reach forErrorHandlerin a host that has no exception pipeline of its own.
You are reading the PHP Core v1.0 documentation.