Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2013 19:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5357469 to your computer and use it in GitHub Desktop.
Save anonymous/5357469 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
const RESPONSE_SIZE = 20; // in megabytes
$app = function ($request, $response) {
$data = str_repeat(chr(rand(32,126)), RESPONSE_SIZE * 1024 * 1024);
print sprintf("Allocated memory usage: %s, Memory Limit: %d, PID: %d\n",
number_format(memory_get_usage()),
ini_get("memory_limit"),
getmypid()
);
$response->writeHead(200, array('Content-Type' => 'text/plain'));
$response->end($data);
unset($data);
};
// Make sure garbage collection is there, and enabled
if(!function_exists('gc_enable'))
die("Please use PHP 5.3+ with Garbage Collection enabled");
gc_enable();
// Taken from React examples.
$loop = React\EventLoop\Factory::create();
$socket = new React\Socket\Server($loop);
$http = new React\Http\Server($socket, $loop);
$http->on('request', $app);
echo "Server running at http://127.0.0.1:1337\n";
$socket->listen(1337);
$loop->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment