baraja-core / shutdown-terminator
Registers handlers that run at the end of the request.
Installs: 50 862
Dependents: 2
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
Requires (Dev)
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^1.0
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-nette: ^1.0
- phpstan/phpstan-strict-rules: ^1.0
- roave/security-advisories: dev-master
- spaze/phpstan-disallowed-calls: ^2.0
This package is auto-updated.
Last update: 2024-12-08 18:26:05 UTC
README
Registers handlers that run at the end of the request.
Idea
When processing more complex PHP applications, we often need to perform some operations at the end of the script run. Most often saving states to the database, sending logs and processing error states.
This package provides a simple interface to accomplish this.
The Terminator automatically reserves the operating memory so that it is possible to process handlers even in the event that the script is forcibly terminated due to memory exhaustion. Handlers call each other when you use die
or exit
in your code.
📦 Installation
It's best to use Composer for installation, and you can also find the package on Packagist and GitHub.
To install, simply use the command:
$ composer require baraja-core/shutdown-terminator
You can use the package manually by creating an instance of the internal classes, or register a DIC extension to link the services directly to the Nette Framework.
How to use
In your class for which you want to call a method after the script exits, simply implement the TerminatorHandler
interface and register the handler:
class MyLogger implements \Baraja\ShutdownTerminator\TerminatorHandler { public function __construct() { // register this service to Terminator Terminator::addHandler($this); } public function processTerminatorHandler(): void { // this logic will be called by Terminator. } }
Configuration
The addHandler()
method supports handler registration, for which you can add your own priority and reserved RAM limit.
📄 License
baraja-core/shutdown-terminator
is licensed under the MIT license. See the LICENSE file for more details.