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
+20-2Lines changed: 20 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ Utilize Laravel Processes to run PHP code asynchronously.
4
4
## What really is this?
5
5
[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:
6
6
- 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])
8
8
- Silent execution: no built-in result-checking, check the results yourself (e.g. via database)
9
9
10
10
## Installation
@@ -14,7 +14,25 @@ Utilize Laravel Processes to run PHP code asynchronously.
14
14
Please see `CHANGELOG.md`.
15
15
16
16
## 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.
0 commit comments