Permalink
Browse files

Add test scripts to check for memory issues

  • Loading branch information...
1 parent d089ef9 commit b729b57a09b5790c9e8622dc3e7ac87949c2b0cf @igorw igorw committed Dec 14, 2012
Showing with 59 additions and 0 deletions.
  1. +28 −0 examples/tests/memory/client.php
  2. +31 −0 examples/tests/memory/server.php
@@ -0,0 +1,28 @@
+<?php
+
+// script to check for memory leaks
+
+require __DIR__.'/../../../vendor/autoload.php';
+
+$loop = new React\EventLoop\StreamSelectLoop();
+
+$i = 0;
+
+$loop->addPeriodicTimer(0.001, function () use ($loop, &$i) {
+ $i++;
+
+ $client = new DNode\DNode($loop);
+ $client->connect(7070, function ($remote, $conn) {
+ $remote->zing(33, function ($n) use ($conn) {
+ $conn->end();
+ });
+ });
+});
+
+$loop->addPeriodicTimer(2, function () use (&$i) {
+ $kmem = memory_get_usage(true) / 1024;
+ echo "Run: $i\n";
+ echo "Memory: $kmem KiB\n";
+});
+
+$loop->run();
@@ -0,0 +1,31 @@
+<?php
+
+// script to check for memory leaks
+
+require __DIR__.'/../../../vendor/autoload.php';
+
+$loop = new React\EventLoop\StreamSelectLoop();
+
+class Zinger
+{
+ public $i = 0;
+
+ public function zing($n, $callback)
+ {
+ $this->i++;
+ $callback($n * 100);
+ }
+}
+
+$zinger = new Zinger();
+
+$server = new DNode\DNode($loop, $zinger);
+$server->listen(7070);
+
+$loop->addPeriodicTimer(2, function () use ($zinger) {
+ $kmem = memory_get_usage(true) / 1024;
+ echo "Run: {$zinger->i}\n";
+ echo "Memory: $kmem KiB\n";
+});
+
+$loop->run();

0 comments on commit b729b57

Please sign in to comment.