blackfireio / php-sdk

The Blackfire PHP SDK
https://blackfire.io
MIT License
150 stars 22 forks source link

Fixed ReactHttpServer #27

Closed Triasto closed 7 years ago

Triasto commented 7 years ago

I was creating a microservice and wanted to compare different methods.

While profiling I discovered that the /Blackfire/Bridge/ReactHttpServer was outdated.

After some modifications I was able to get it working.

This is my first public pull request, tips and improvements are more then welcome.

<?php
include_once __DIR__ . '/vendor/autoload.php';
$blackfire = new Blackfire\Bridge\ReactHttpServer();

$loop = React\EventLoop\Factory::create();

$server = new \React\Http\Server(function (\Psr\Http\Message\ServerRequestInterface $request) use ($blackfire) {
    $blackfire->handleRequest($request);
    sleep(5);
    $response = new \React\Http\Response(
        200,
        $blackfire->handleHeaders(['Content-Type' => 'text/plain']),
        "Hello World!\n"
    );

    return $response;
});

$socket = new React\Socket\Server('0.0.0.0:8080', $loop);

$server->listen($socket);

$loop->run();
romainneutron commented 7 years ago

Hello,

Thanks for your contribution, it has been merged and tweaked as of 6b83355d860490b0bdf582b82cd6a43a7649f2e2

romainneutron commented 7 years ago

Released as of v1.9.0