-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.php
More file actions
37 lines (30 loc) · 1 KB
/
demo.php
File metadata and controls
37 lines (30 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
require_once 'vendor/autoload.php';
use Terremoth\Async\Process;
use Terremoth\Async\PhpFile;
$process = new Process();
echo date('c') . ' :: Sending process. You should not wait any longer to see next message: ' . PHP_EOL;
try {
$age = 30;
$name = 'John Doe';
$fruits = ['orange', 'apple', 'grape'];
$process->send(function () use ($age, $name, $fruits) {
sleep(5);
echo 123; // you should not see this anywhere
file_put_contents(
'demo.txt',
"Age: $age\nName: $name\nFruits: " . implode(', ', $fruits) . ' - ' . date('c')
);
});
} catch (Exception $e) {
echo $e->getMessage();
}
echo date('c') . ' :: This is the next message' . PHP_EOL;
echo date('c') . ' :: Now let\'s process a file that takes a long time...' . PHP_EOL;
try {
$file = new PhpFile(__DIR__ . DIRECTORY_SEPARATOR . 'time-wasting-file.php');
$file->run();
echo date('c') . ' :: Ended...' . PHP_EOL;
} catch (Exception $e) {
echo $e->getMessage();
}