Download the PHP package nabeghe/cronark without Composer
On this page you can find all versions of the php package nabeghe/cronark. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nabeghe/cronark
More information about nabeghe/cronark
Files in nabeghe/cronark
Package cronark
Short Description A lightweight, cron-based background job scheduler and worker manager for PHP.
License MIT
Homepage https://github.com/nabeghe/cronark
Informations about the package cronark
Cronark
A lightweight, cron-based background job scheduler and worker manager for PHP.
Cronark provides a simple yet powerful solution for running background jobs in PHP applications. Unlike traditional queue systems that require external services (Redis, RabbitMQ, Beanstalkd), Cronark works with just cron and minimal storage; making it perfect for shared hosting, small to medium projects, or anywhere you want to avoid infrastructure complexity.
๐ฏ Why Cronark?
The Problem with Traditional Queue Systems
Most PHP queue solutions come with significant challenges:
- โ Infrastructure Overhead: Require Redis, RabbitMQ, or other external services
- โ Shared Hosting: Not available on most shared hosting environments
- โ Complexity: Learning curve, configuration, and maintenance burden
- โ Resource Heavy: Memory consumption and process management complexity
- โ Overkill: Too much for simple background job needs
The Cronark Solution
Cronark takes a different approach:
- โ Zero Dependencies: Just PHP 8.1+ and cron (available everywhere)
- โ Shared Hosting Friendly: Works on any hosting with cron access
- โ Simple Setup: Define jobs, register with cron, done
- โ Lightweight: Minimal resource footprint
- โ Process-Safe: Prevents duplicate worker execution automatically
- โ Flexible Storage: File-based by default, easily customizable to database or Redis
๐ฆ Installation
Install via Composer:
Requirements:
- PHP 8.1 or higher
- Cron access (available on virtually all hosting providers)
๐ Quick Start
1. Create a Job
2. Register the Job
Create a worker file (e.g., worker.php):
3. Setup Cron
Add to your crontab:
That's it! Your jobs will now run continuously in the background.
๐จ Features
Multiple Workers Run different workers for different job types:
Process Management
Cronark automatically prevents duplicate workers:
Job Ordering
Control job execution order:
Custom Storage
Implement your own storage backend (Database, Redis, Memcached, etc.):
Built-in Storage:
- File-based (default): Zero setup, works everywhere
- Custom: Implement StorageInterface for database, Redis, etc.
Lifecycle Hooks
Customize worker behavior:
Performance Tuning
Control CPU usage by adding delay between job executions:
When to use delay:
- โ Shared hosting with CPU limits
- โ Light/fast jobs (< 10ms execution time)
- โ Rate limiting external API calls
- โ Reducing database connection pressure
When NOT to use delay:
- โ Heavy/slow jobs (they already have natural delay)
- โ Real-time processing requirements
- โ Time-sensitive operations
Recommended values:
- 0 โ No delay (default, maximum speed)
- 10000 โ 10ms (~100 jobs/sec, near real-time)
- 50000 โ 50ms (~20 jobs/sec, balanced)
- 100000 โ 100ms (~10 jobs/sec, CPU friendly)
๐ How It Works
Architecture
- Cron Trigger: Cron executes worker script every minute (or your interval)
- Duplicate Prevention: Worker checks if it's already running (via PID + script path)
- Infinite Loop: If not running, worker enters infinite loop
- Job Execution: Executes jobs sequentially in a circular fashion
- Graceful Shutdown: Monitors PID to allow graceful termination
Process Flow
Job Wrapping
Jobs execute in a circular fashion:
This ensures all jobs get executed repeatedly without any sitting idle.
๐ง Advanced Usage
Jobs can throw exceptions; they won't stop the worker:
Error Handling
Worker Isolation
Each worker maintains its own state:
Cron Schedule Examples
Deployment on Shared Hosting
Most shared hosting providers (cPanel, Plesk) offer cron job access:
cPanel:
- Go to "Cron Jobs"
- Add: * php /home/username/public_html/worker.php
Plesk:
- Go to "Scheduled Tasks"
- Add command: php /var/www/vhosts/domain.com/worker.php
- Set schedule: Every minute
๐งช Testing
Test Coverage: 67 tests with full coverage of all core functionality.
๐ก๏ธ Reliability
Duplicate Prevention
Cronark uses PID + Script Path verification to prevent duplicate workers:
Crash Recovery
If worker crashes, cron will restart it on next trigger:
Atomic Storage
File operations use LOCK_EX for atomic writes:
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ก Use Cases
Perfect for:
- Shared Hosting Projects: No Redis/RabbitMQ required
- Small to Medium Apps: When full queue infrastructure is overkill
- Email Processing: Send newsletters, notifications
- Data Import/Export: Process CSV files, API sync
- Report Generation: Periodic reports, analytics
- Cleanup Tasks: Temp file cleanup, log rotation
- Social Media Posting: Schedule posts, fetch feeds
- Database Maintenance: Backups, optimization
- Any Recurring Task: If it needs to run regularly, Cronark can handle it
๐ Documentation
Core Classes
Cronark: Main scheduler classJob: Interface for all jobsProcess: Cross-platform process utilitiesStorage: File-based storage implementationStorageInterface: Storage contract for custom backends
Key Methods
โ ๏ธ Important Notes
- Execution Time: Workers run indefinitely; ensure your hosting allows long-running processes
- Memory: Monitor memory usage if jobs process large datasets
- Error Handling: Always implement proper error handling in jobs
- Logging: Use the
print()method or implement custom logging - Database Connections: Reconnect to database in
onJobCreating()hook to avoid timeout issues
๐ Show Your Support
If you find Cronark useful, please:
- โญ Star the repository
- ๐ Report bugs
- ๐ก Suggest features
- ๐ Improve documentation
- ๐ Submit pull requests
๐ License
Licensed under the MIT license, see LICENSE.md for details.
Made with โค๏ธ by (Nabeghe)[https://github.com/nabeghe]
Cronark - Simple, Reliable, Zero-Dependency Background Jobs for PHP