lang/php

PHP reactPHP helloWorld

C/H 2018. 6. 14. 08:30

ReactPHP

composer require 'react/react=*'
vi server.php
<?php
require_once(__DIR__. '/vendor/autoload.php');

$i = 0;
$app = function ($request, $response) use ($i) {
    $response->writeHead(200, array('Content-Type' => 'text/html'));
    $response->end("Hello World");
    $i++;
};

$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();
php server.php
Server running at http://127.0.0.1:1337

# other shell
ab -n 10000 -c 10 http://127.0.0.1:1337/
...
Concurrency Level:      10
Time taken for tests:   1.943 seconds
Complete requests:      10000
Failed requests:        0
Keep-Alive requests:    0
Total transferred:      1200000 bytes
HTML transferred:       210000 bytes
Requests per second:    5146.61 [#/sec] (mean)
Time per request:       1.943 [ms] (mean)
Time per request:       0.194 [ms] (mean, across all concurrent requests)
Transfer rate:          603.12 [Kbytes/sec] received

Connection Times (ms)
                min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    2   0.2      2       4
Waiting:        1    2   0.2      2       4
Total:          1    2   0.2      2       4

Percentage of the requests served within a certain time (ms)
    50%      2
    66%      2
    75%      2
    80%      2
    90%      2
    95%      2
    98%      3
    99%      3
    100%      4 (longest request)


반응형

'lang > php' 카테고리의 다른 글

Simple PHP Web Scraper Guotte  (0) 2018.06.29
PHP Laravel Framework helloWorld  (0) 2018.06.15
PHP workman Container helloWorld  (0) 2018.06.12
php codeignier3 framework helloWorld  (0) 2018.06.11
PHP Slim Framework helloWorld  (0) 2018.06.07