Skip to content

Commit 84fbe78

Browse files
committed
Improve benchmarking instructions and dangling memory references
1 parent 7aa08f0 commit 84fbe78

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

examples/99-server-benchmark-download.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
<?php
22

3+
// A simple HTTP web server that can be used to benchmark requests per second and download speed
4+
//
35
// $ php examples/99-server-benchmark-download.php 8080
6+
//
7+
// This example runs the web server on a single CPU core in order to measure the
8+
// per core performance.
9+
//
410
// $ curl http://localhost:8080/10g.bin > /dev/null
511
// $ wget http://localhost:8080/10g.bin -O /dev/null
6-
// $ ab -n10 -c10 http://localhost:8080/1g.bin
7-
// $ docker run -it --rm --net=host jordi/ab -n100000 -c10 http://localhost:8080/
8-
// $ docker run -it --rm --net=host jordi/ab -n10 -c10 http://localhost:8080/1g.bin
12+
// $ ab -n10 -c10 -k http://localhost:8080/1g.bin
13+
// $ docker run -it --rm --net=host jordi/ab -n100000 -c10 -k http://localhost:8080/
14+
// $ docker run -it --rm --net=host jordi/ab -n10 -c10 -k http://localhost:8080/1g.bin
15+
// $ docker run -it --rm --net=host skandyla/wrk -t8 -c10 -d20 http://localhost:8080/
916

1017
use Evenement\EventEmitter;
1118
use Psr\Http\Message\ServerRequestInterface;

src/Io/RequestHeaderParser.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ public function handle(ConnectionInterface $conn)
106106
$stream->close();
107107
}
108108
});
109-
110-
$conn->on('close', function () use (&$buffer, &$fn) {
111-
$fn = $buffer = null;
112-
});
113109
}
114110

115111
/**

src/Io/StreamingServer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,8 @@ public function handleResponse(ConnectionInterface $connection, ServerRequestInt
367367
if ($persist) {
368368
$body->pipe($connection, array('end' => false));
369369
$parser = $this->parser;
370-
$body->on('end', function () use ($connection, $parser) {
370+
$body->on('end', function () use ($connection, $parser, $body) {
371+
$connection->removeListener('close', array($body, 'close'));
371372
$parser->handle($connection);
372373
});
373374
} else {

tests/Io/StreamingServerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,9 @@ public function testNewConnectionWillInvokeParserTwiceAfterInvokingRequestHandle
30013001
// pretend parser just finished parsing
30023002
$server->handleRequest($this->connection, $request);
30033003

3004+
$this->assertCount(2, $this->connection->listeners('close'));
30043005
$body->end();
3006+
$this->assertCount(1, $this->connection->listeners('close'));
30053007
}
30063008

30073009
private function createGetRequest()

0 commit comments

Comments
 (0)