Skip to content

Commit 1ed6729

Browse files
committed
README: describe task time limits
1 parent 1580159 commit 1ed6729

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ $task->start();
6969
// the task is now run in another PHP process, and will not report back to this PHP process.
7070
```
7171

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!)
87+
$task->withoutTimeLimit()->start();
88+
```
89+
7290
## Testing
7391
PHPUnit via Composer script:
7492
```sh

0 commit comments

Comments
 (0)