Skip to content

Commit 041a864

Browse files
committed
Provide more details in the README
1 parent 926591e commit 041a864

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Utilize Laravel Processes to run PHP code asynchronously.
44
## What really is this?
55
[Laravel Processes](https://laravel.com/docs/10.x/processes) was first introduced in Laravel 10. This library wraps around `Process::start()` to let you execute code in the background to achieve async, albeit with some caveats:
66
- You may only execute PHP code
7-
- Restrictions from SC apply (see)
7+
- Restrictions from `laravel/serializable-closure` apply (see (their README)[https://github.com/laravel/serializable-closure])
88
- Silent execution: no built-in result-checking, check the results yourself (e.g. via database)
99

1010
## Installation
@@ -14,7 +14,25 @@ Utilize Laravel Processes to run PHP code asynchronously.
1414
Please see `CHANGELOG.md`.
1515

1616
## Example code
17-
(WIP)
17+
Tasks can be defined as PHP closures, or (recommended) as an instance of a class that implements `AsyncTaskInterface`.
18+
19+
A very simple example task to write Hello World to a file:
20+
21+
```php
22+
// define the task...
23+
$target = "document.txt";
24+
$task = new AsyncTask(function () use ($target) {
25+
$fp = fopen($target, "w");
26+
fwrite($fp, "Hello World!!");
27+
fflush($fp);
28+
fclose($fp);
29+
});
30+
31+
// then start it.
32+
$task->start();
33+
34+
// the task is now run in another PHP process, and will not report back to this PHP process.
35+
```
1836

1937
## Testing
2038
PHPUnit via Composer script:

0 commit comments

Comments
 (0)