Download the PHP package abhishekdas/shutdown-scheduler without Composer
On this page you can find all versions of the php package abhishekdas/shutdown-scheduler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download abhishekdas/shutdown-scheduler
More information about abhishekdas/shutdown-scheduler
Files in abhishekdas/shutdown-scheduler
Package shutdown-scheduler
Short Description A lightweight PHP library for managing shutdown events in your applications
License GPL-3.0-or-later
Homepage https://github.com/abhishekdas/shutdown-scheduler
Informations about the package shutdown-scheduler
Shutdown Scheduler
A lightweight PHP library for managing shutdown events in your applications. Shutdown Scheduler allows you to register callbacks that will execute when your script ends, ensuring proper cleanup and resource handling even during unexpected script termination.
📋 Table of Contents
- Features
- Installation
- Basic Usage
- Advanced Examples
- Cron Job Implementation
- API Reference
- Development
- Running Tests
- Coding Standards
- Contributing
- License
✨ Features
- Reliable Execution: Callbacks are guaranteed to run when the script terminates
- Event-Based System: Register multiple shutdown events with unique names
- Simple API: Intuitive methods for registering and unregistering callbacks
- Error Handling: Built-in validation for callbacks and event names
- Resource Cleanup: Perfect for database connections, file handlers, and temporary resources
🚀 Installation
Manual Installation
Simply include the ShutdownScheduler.php file in your project:
Composer (Recommended)
Add the package to your composer.json file:
Then run:
🔰 Basic Usage
Here's a simple example of how to use Shutdown Scheduler:
🔄 Advanced Examples
Cron Job Implementation
The following example demonstrates how to use the ShutdownScheduler in a cron job to prevent multiple instances from running simultaneously:
📘 API Reference
AbhishekDas\ShutdownScheduler\ShutdownScheduler Class
Constructor
Initializes the ShutdownScheduler and registers the internal shutdown function.
Methods
registerShutdownEvent(string $eventName, callable $callback, mixed ...$params)
Registers a shutdown event with a callback function.
-
Parameters:
$eventName(string): A unique name for this shutdown event$callback(callable): The function to be called on shutdown...$params(mixed): Optional parameters to pass to the callback
- Returns:
bool-trueon success,falseon failure
unregisterShutdownEvent(string $eventName)
Unregisters a previously registered shutdown event.
- Parameters:
$eventName(string): The name of the event to unregister
callRegisteredShutdown()
Internal method that executes all registered callbacks when the script terminates.
� Development
Running Tests
This project uses PHPUnit for testing. To run the tests:
-
Install development dependencies:
- Run the test suite:
Coding Standards
We follow the PSR-12 coding standard. To check your code against these standards:
To automatically fix some coding standard issues:
�👥 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
📄 License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Made with ❤️ by Abhishek Das