silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 718 forks source link

Using Swoole with Silex #1328

Closed casoetan closed 8 years ago

casoetan commented 8 years ago

Hi there.

Any ideas on how to use Swoole - http://www.swoole.com - with Silex?

GromNaN commented 8 years ago

Swoole is some kind of PHP framework for asynchronous & parallel network communications, written as a C extension for PHP. The framework contains an HttpServer component that is equivalent to the HttpKernel of Symfony. If you can bridge Request and Response objects between both projects, then they can be used together. Providing a generic Request and Response classes is the purpose of PSR-7 and is implemented in the Symfony PSR-7 Bridge. An issue has been created on the Swoole repository: https://github.com/swoole/swoole-src/issues/559.

$serv = new swoole_http_server("127.0.0.1", 9502);
$app = new Silex\Application();

$serv->on('Request', function($request, $response) use ($app) {
    $symfonyRequest = convertRequest($request);
    $symfonyResponse = $app->handle($symfonyRequest);
    $response = convertResponse($symfonyResponse);
});

// Or maybe one day with PSR-7

$serv->on('Request', [$app, 'handle']);

Otherwise, you can also use parts of Silex separately with Swoole :

ragboyjr commented 8 years ago

@casoetan, did @GromNaN answer your question sufficiently?

casoetan commented 8 years ago

Yes he did.

Thanks

On May 3, 2016, at 01:05, ragboyjr notifications@github.com wrote:

@casoetan https://github.com/casoetan, did @GromNaN https://github.com/GromNaN answer your question sufficiently?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/silexphp/Silex/issues/1328#issuecomment-216400383

kcloze commented 7 years ago

I made a skeleton with swoole as below: https://github.com/kcloze/slim-swoole

casoetan commented 7 years ago

nice work @kcloze, but this is for slim not silex. Waiting...