Download the PHP package websolutionfalcon/lockable-command without Composer
On this page you can find all versions of the php package websolutionfalcon/lockable-command. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download websolutionfalcon/lockable-command
More information about websolutionfalcon/lockable-command
Files in websolutionfalcon/lockable-command
Package lockable-command
Short Description A Laravel package for locking and unlocking command execution without code deployment. Perfect for temporarily disabling scheduled commands during server overload or maintenance.
License MIT
Homepage https://github.com/websolutionfalcon/lockable-command
Informations about the package lockable-command
Laravel Lockable Command
A simple Laravel package that allows you to lock and unlock command execution. Perfect for scenarios where you have commands running via cronjobs and need to temporarily disable them without deploying code changes. For example, if your server is overloaded by a scheduled command, you can simply lock it to prevent further executions until the issue is resolved.
Installation
You can install the package via composer:
Optionally, you can publish the config file with:
This will create a config/lockable-command.php file where you can customize the lock file path and extension.
Usage
1. Creating a Lockable Command
To make your command lockable, extend the LockableCommand class instead of the default Laravel Command class:
2. Locking and Unlocking Commands
Use the command:locker command to lock or unlock any lockable command:
Lock a command:
Unlock a command:
When a command is locked, attempting to run it will display an error message and prevent execution:
3. Configuration
The package uses a configuration file to customize behavior. Publish it to modify:
You can also set these values in your .env file:
How It Works
When you lock a command, the package creates a lock file in the configured directory. Before executing, any LockableCommand checks for the existence of its lock file. If found, execution is prevented. Unlocking simply removes the lock file, allowing the command to run normally.
The lock files are named based on the command signature with colons replaced by underscores (e.g., reports:process becomes reports_process.lock).
Use Cases
- Overloaded Server: Temporarily disable resource-intensive scheduled commands during high traffic
- Maintenance: Prevent specific commands from running during database migrations or system updates
- Debugging: Lock commands while investigating issues without modifying cron schedules
- Gradual Rollout: Control which commands run in different environments without code changes
Testing
The package includes comprehensive tests. First, install dependencies:
Then run the tests:
Run tests with coverage:
Run code quality checks:
Requirements
- PHP 8.1 or higher
- Laravel 11.0 or higher
API Reference
LockableCommand
Your commands should extend this class to make them lockable.
Methods:
isLocked(): bool- Check if the command is currently lockedisEnabled(): bool- Check if the command can be executed (returns false if locked)getLockPath(): string- Get the lock file path for this command
CommandLocker
The artisan command for locking/unlocking commands.
Signature:
Arguments:
action- Either "lock" or "unlock"target- The name of the command to lock/unlock
Example:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Contributions are welcome! Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of lockable-command with dependencies
illuminate/collections Version ^11.0
illuminate/console Version ^11.0
illuminate/support Version ^11.0