| 1 |
# PHP SQLite Job Queue |
| 2 |
|
| 3 |
A minimal job queue library written in PHP that persists data with SQLite. |
| 4 |
|
| 5 |
Use it for small projects / prototypes with at most hundreds or thousands of jobs. |
| 6 |
|
| 7 |
## Install |
| 8 |
|
| 9 |
composer require mgleis/php-sqlite-job-queue |
| 10 |
|
| 11 |
## Usage |
| 12 |
|
| 13 |
### The Main Use Cases |
| 14 |
|
| 15 |
#### Add a new job |
| 16 |
|
| 17 |
$queue = new Queue('queue.sqlite'); |
| 18 |
$queue->push("a string"); |
| 19 |
$queue->push(["an" => "array"]); |
| 20 |
$queue->push([0, 1, 2, 3, 4]); |
| 21 |
$queue->push(['type' => 'SendEmail', 'to' => '...']); |
| 22 |
|
| 23 |
#### Process jobs with workers |
| 24 |
|
| 25 |
$worker = new Worker($queue); |
| 26 |
$worker->process(function(Job $job) { |
| 27 |
$payload = $job->payload; |
| 28 |
if ($payload['type'] == 'SendEmail') |
| 29 |
send_email(...); |
| 30 |
}); |
| 31 |
|
| 32 |
#### Worker Configuration |
| 33 |
|
| 34 |
You have several options to configure the worker. The options should be self-explanatory: |
| 35 |
|
| 36 |
// optional configuration |
| 37 |
$worker |
| 38 |
->withMaxTotalRuntimeInSeconds(60) |
| 39 |
->withMaxJobCount(100) |
| 40 |
->withSleepTimeBetweenJobsInMilliseconds(1) |
| 41 |
->withSleepTimeOnEmptyQueueInMilliseconds(100); |
| 42 |
|
| 43 |
### Edge Cases |
| 44 |
|
| 45 |
### Determine Size of the queue |
| 46 |
|
| 47 |
$size = $queue->size(); |
| 48 |
|
| 49 |
### Get a specific job |
| 50 |
|
| 51 |
$job = $queue->get(12345); |
| 52 |
|
| 53 |
### Handling Errors |
| 54 |
TBD |
| 55 |
|
| 56 |
### Handling Timeouts (reserved jobs) |
| 57 |
TBD |
| 58 |
|
| 59 |
### Handling database locks |
| 60 |
TBD |
| 61 |
|
| 62 |
|