You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-1Lines changed: 29 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -13,13 +13,17 @@ Utilize Laravel Processes to run PHP code asynchronously.
13
13
- Restrictions from `laravel/serializable-closure` apply (see [their README](https://github.com/laravel/serializable-closure))
14
14
- Hands-off execution: no built-in result-checking, check the results yourself (e.g. via database, file cache, etc)
15
15
16
+
This library internally uses an Artisan command to run the async code, which is similar to Laravel 11 [Concurrency](https://laravel.com/docs/11.x/concurrency).
17
+
16
18
## Why should I want this?
17
19
This library is very helpful for these cases:
18
-
- You want a minimal-setup async for easy vertical scaling
20
+
- You want a cross-platform minimal-setup async for easy vertical scaling
19
21
- You want to start quick-and-dirty async tasks right now (e.g. prefetching resources, pinging remote, etc.)
20
22
- Best is if your task only has very few lines of code
21
23
- Laravel 11 [Concurrency](https://laravel.com/docs/11.x/concurrency) is too limiting; e.g.:
22
24
- You want to do something else while waiting for results
25
+
- You want to conveniently limit the max (real) execution time of the concurrent tasks
26
+
- And perhaps more!
23
27
24
28
Of course, if you are considering extreme scaling (e.g. Redis queues in Laravel, multi-worker clusters, etc.) or guaranteed task execution, then this library is obviously not for you.
This library supports Unix and Windows; see the Testing section for more details.
34
38
39
+
### Extra requirements for Unix
40
+
If you are on Unix, check that you also have the following:
41
+
- GNU Core Utilities (`coreutils`)
42
+
- MacOS do `brew install coreutils`!
43
+
- Other Unix distros should check if `coreutils` is preinstalled
44
+
35
45
## Change log
36
46
Please see `CHANGELOG.md`.
37
47
@@ -59,6 +69,24 @@ $task->start();
59
69
// the task is now run in another PHP process, and will not report back to this PHP process.
60
70
```
61
71
72
+
### Task time limits
73
+
You can set task time limits before you start them, but you cannot change them after the tasks are started. When the time limit is reached, the async task is killed.
74
+
75
+
The default time limit is 30 real seconds. You can also choose to not set any time limit, in this case the (CLI) PHP `max_execution_time` directive will control the time limit.
76
+
77
+
Note: `AsyncTaskInterface` contains an implementable method `handleTimeout` for you to define timeout-related cleanups (e.g. write to some log that the task has timed out). This method is still called when the PHP `max_execution_time` directive is triggered.
78
+
79
+
```php
80
+
// start with the default time limit...
81
+
$task->start();
82
+
83
+
// start task with a different time limit...
84
+
$task->withTimeLimit(15)->start();
85
+
86
+
// ...or not have any limits at all (beware of orphaned processes!)
0 commit comments