What is cron-express?
cron-express is a lightweight PHP library for creating and managing task schedulers (cron-like jobs) directly in your application code. It allows you to set task execution frequency using human-readable syntax (e.g., 'every 10 minutes', 'daily at 14:30') instead of complex cron expressions. The library is ideal for Laravel, Symfony frameworks, and plain PHP.
Why do you need a task scheduler?
In web development, background operations are often required: sending email newsletters, clearing cache, generating reports, syncing data with APIs. Using system cron requires server access and editing crontab. cron-express solves this problem by allowing you to manage tasks programmatically — all settings are stored in PHP files, simplifying deployment and versioning.
Installation
Install the library via Composer:
composer require mtdowling/cron-expressionOr for a more advanced scheduler with human-readable syntax:
composer require dragonmantank/cron-expressionAfter installation, include the Composer autoloader:
require 'vendor/autoload.php';Main Features
- Human-readable intervals: 'every 5 minutes', 'every hour', 'daily at 10:00', 'weekly on Monday'
- Flexible time configuration: support for time zones, days of the week, months
- Framework integration: ready-made solutions for Laravel (Artisan) and Symfony (Console)
- Security: prevention of simultaneous task execution (overlapping protection)
- Logging: built-in support for writing execution results to a file or database
PHP Code Example
<?phprequire 'vendor/autoload.php';
use Cron\\CronExpression;
// Create a task: run every 30 minutes$cron = new CronExpression('*/30 * * * *');
// Check if it needs to run nowif ($cron->isDue(new DateTime())) { echo 'Running task: clearing cache'; // Your code clearCache();}
// Example with human-readable syntax (requires dragonmantank/cron-expression library)$expression = 'every 2 hours';$cron = CronExpression::factory($expression);echo $cron->getNextRunDate()->format('Y-m-d H:i:s'); // 2025-04-01 14:00:00?>When to use cron-express?
- Web applications: for sending notifications, updating statistics
- API services: periodic synchronization with external services
- Development: testing cron tasks locally without configuring system cron
- Deployment: storing the schedule in Git along with the code
The library is especially useful in projects where centralized management of background processes is important. It lowers the entry barrier for beginners and speeds up development for experienced programmers.
Also in library
Authorization and Authentication in Rust: Libraries and Tools
HTTP Client for JavaScript (Node.js): Top Libraries for Working with API
RapidJSON for C++: Complete Guide with Examples
Caching in Go (Golang): Redis, Group, and In-Memory Caching