Default Configuration
Queue workers are configured in yourconfig/nativephp.php file. By default, NativePHP starts a single queue worker that processes the default queue:
config/nativephp.php
NativePHP automatically sets the default queue connection to
database and uses the SQLite database for queue storage.Configuration Options
Each queue worker accepts the following configuration options:| Option | Type | Description |
|---|---|---|
queues | array | Array of queue names to process (e.g., ['default', 'emails', 'notifications']) |
memory_limit | int | Maximum memory in MB the worker can use (default: 128) |
timeout | int | Maximum seconds a job can run before timing out (default: 60) |
sleep | int|float | Seconds to sleep when no jobs are available (default: 3) |
Multiple Queue Workers
You can configure multiple queue workers to handle different queues or priorities:config/nativephp.php
Programmatic Control
You can start and stop queue workers programmatically using theQueueWorker contract:
Starting a Worker
Stopping a Worker
How It Works
Understanding Queue Worker Behavior
Understanding Queue Worker Behavior
When your NativePHP application starts:
- Development Mode: Workers use
queue:listencommand, which automatically reloads when code changes - Production Mode: Workers use
queue:workcommand for better performance - Process Management: Each worker runs as a persistent child process with its own memory limit
- Auto-Recovery: If a worker crashes, it will be restarted automatically
--quiet flag to minimize output.Dispatching Jobs
Dispatch jobs as you normally would in Laravel:Best Practices
- Memory Limits: Set appropriate memory limits based on your job requirements
- Timeout Values: Ensure timeouts are longer than your longest-running job
- Sleep Duration: Lower sleep values increase responsiveness but use more CPU
- Queue Separation: Use separate queues for different job priorities or types
Troubleshooting
Jobs Not Processing
If jobs aren’t being processed:- Check that your queue connection is set to
database - Verify the queue worker is running for the correct queue name
- Check the
failed_jobstable for any failed jobs - Review application logs for errors
High Memory Usage
If workers are using too much memory:- Lower the
memory_limitconfiguration - Reduce the number of concurrent workers
- Optimize your job code to use less memory
- Consider breaking large jobs into smaller chunks
Worker Crashes
If workers keep crashing:- Check application logs for error messages
- Increase the
timeoutvalue if jobs are timing out - Increase the
memory_limitif workers are running out of memory - Review your job code for memory leaks or infinite loops