1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
const MB = 1048576; |
4
|
|
|
const I = 100000; |
5
|
|
|
|
6
|
|
|
function show_memory($message = '') |
7
|
|
|
{ |
8
|
|
|
echo '------------------------------------------', PHP_EOL; |
9
|
|
|
echo $message, PHP_EOL; |
10
|
|
|
echo '------------------------------------------', PHP_EOL; |
11
|
|
|
echo 'Current memory usage: ', \memory_get_usage() / MB, 'MB', PHP_EOL; |
12
|
|
|
echo 'Peak memory usage: ', \memory_get_peak_usage() / MB, 'MB', PHP_EOL; |
13
|
|
|
echo 'Current real memory usage: ', \memory_get_usage(true) / MB, 'MB', PHP_EOL; |
14
|
|
|
echo 'Peak real memory usage: ', \memory_get_peak_usage(true) / MB, 'MB', PHP_EOL; |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
show_memory('Bare init'); |
18
|
|
|
|
19
|
|
|
require \dirname(__DIR__) . '/vendor/autoload.php'; |
20
|
|
|
|
21
|
|
|
use React\EventLoop\Factory as EventLoopFactory; |
22
|
|
|
use React\EventLoop\TimerInterface; |
23
|
|
|
use WyriHaximus\React\ChildProcess\Messenger\Factory as MessengerFactory; |
24
|
|
|
use WyriHaximus\React\ChildProcess\Messenger\Messages\Factory as MessagesFactory; |
25
|
|
|
use WyriHaximus\React\ChildProcess\Messenger\Messenger; |
26
|
|
|
|
27
|
|
|
show_memory('Begin'); |
28
|
|
|
|
29
|
|
|
$loop = EventLoopFactory::create(); |
|
|
|
|
30
|
|
|
|
31
|
|
|
MessengerFactory::parentFromClass(\WyriHaximus\React\ChildProcess\Messenger\ReturnChild::class, $loop)->then(function (Messenger $messenger) use ($loop) { |
32
|
|
|
$messenger->on('error', function ($e) { |
33
|
|
|
echo 'Error: ', \var_export($e, true), PHP_EOL; |
34
|
|
|
}); |
35
|
|
|
|
36
|
|
|
$i = 0; |
37
|
|
|
$loop->addPeriodicTimer(0.00001, function (TimerInterface $timer) use (&$i, $messenger, $loop) { |
38
|
|
|
if ($i >= I) { |
39
|
|
|
$loop->cancelTimer($timer); |
40
|
|
|
$messenger->softTerminate(); |
41
|
|
|
|
42
|
|
|
show_memory('Completed messaging'); |
43
|
|
|
|
44
|
|
|
$loop->addTimer(5, function () { |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
return; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$messenger->rpc(MessagesFactory::rpc('return', [ |
51
|
|
|
'i' => $i, |
52
|
|
|
'time' => \time(), |
53
|
|
|
])); |
54
|
|
|
|
55
|
|
|
$i++; |
56
|
|
|
}); |
57
|
|
|
})->done(); |
58
|
|
|
|
59
|
|
|
$loop->run(); |
60
|
|
|
|
61
|
|
|
show_memory('Done'); |
62
|
|
|
|
63
|
|
|
unset($loop); |
64
|
|
|
$loop = null; |
65
|
|
|
|
66
|
|
|
show_memory('Removed loop'); |
67
|
|
|
|
68
|
|
|
$cycles = \gc_collect_cycles(); |
69
|
|
|
|
70
|
|
|
show_memory('gc_collect_cycles: ' . $cycles); |
71
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.