Skip to content

Commit b729b57

Browse files
committed
Add test scripts to check for memory issues
1 parent d089ef9 commit b729b57

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

examples/tests/memory/client.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
// script to check for memory leaks
4+
5+
require __DIR__.'/../../../vendor/autoload.php';
6+
7+
$loop = new React\EventLoop\StreamSelectLoop();
8+
9+
$i = 0;
10+
11+
$loop->addPeriodicTimer(0.001, function () use ($loop, &$i) {
12+
$i++;
13+
14+
$client = new DNode\DNode($loop);
15+
$client->connect(7070, function ($remote, $conn) {
16+
$remote->zing(33, function ($n) use ($conn) {
17+
$conn->end();
18+
});
19+
});
20+
});
21+
22+
$loop->addPeriodicTimer(2, function () use (&$i) {
23+
$kmem = memory_get_usage(true) / 1024;
24+
echo "Run: $i\n";
25+
echo "Memory: $kmem KiB\n";
26+
});
27+
28+
$loop->run();

examples/tests/memory/server.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
// script to check for memory leaks
4+
5+
require __DIR__.'/../../../vendor/autoload.php';
6+
7+
$loop = new React\EventLoop\StreamSelectLoop();
8+
9+
class Zinger
10+
{
11+
public $i = 0;
12+
13+
public function zing($n, $callback)
14+
{
15+
$this->i++;
16+
$callback($n * 100);
17+
}
18+
}
19+
20+
$zinger = new Zinger();
21+
22+
$server = new DNode\DNode($loop, $zinger);
23+
$server->listen(7070);
24+
25+
$loop->addPeriodicTimer(2, function () use ($zinger) {
26+
$kmem = memory_get_usage(true) / 1024;
27+
echo "Run: {$zinger->i}\n";
28+
echo "Memory: $kmem KiB\n";
29+
});
30+
31+
$loop->run();

0 commit comments

Comments
 (0)