roadrunner-server / roadrunner

🤯 High-performance PHP application server, process manager written in Go and powered with plugins
https://docs.roadrunner.dev
MIT License
7.92k stars 411 forks source link

[Proposition] Standardize integrations #105

Closed Alex-Bond closed 5 years ago

Alex-Bond commented 5 years ago

Hi everyone!

When I was working on Laravel integration got an idea for PHP side of RoarRunner. Right now we tell users to create psr-worker.php file manually and just providing a lot of code. What if we simplify it?

Here is my idea: We create interface IntegrationInterface like this:

interface IntegrationInterface
{
    public function init();

    public function beforeRequest();

    public function processRequest(Request $request): Response;

    public function afterRequest();

    public function shutdown();
}

Move request loop into RoadRunner library and leave in psr-worker.php something like this:

$roadrunner = new RoadRunner();
$integration = new LaravelIntegration(['some' => 'config', 'for' => 'interation']);

$roadrunner->run($integration);

In this case, we simplify the life of developers by removing a lot of things + give a community a chance to work on integrations and fix new problems without telling all users to manually update files.

Any feedback?)

wolfy-j commented 5 years ago

I would avoid doing it until we have solid examples of 2-3 integration, so far integration with Slim, Spiral, Symfony/Laravel differs a lot. This will save a bit of time while the integration creation, but most of issues will happen on later stage.

grachevko commented 5 years ago

I'm :-1: for this integration. All application specific processes must be on application side. I see only one benefit of this, is a quick start. But Integration in this way reduce flexibility for end users whitch also remove any benefits from quick start. You can't fix all user projects problem on your side

In my opinion, creating frameworks integrations for RR is a mistake like framework integrations for Apache/Nginx. Nothing standartize here.

You can create bridges for all frameworks you want to provide quick start and add framework specific suggestions to readme. This well enough for start.

I also suggest to remove PSR dependencies from RR repo to rr-psr-bridge. I wrote client for symony/http-foundation and don't want to install following packages to my project: psr/http-factory, psr/http-message, zendframework/zend-diactoros, but i haven't choice.

wolfy-j commented 5 years ago

I also suggest to remove PSR dependencies from RR repo to rr-psr-bridge. I wrote client for symony/http-foundation and don't want to install following packages to my project: psr/http-factory, psr/http-message, zendframework/zend-diactoros, but i haven't choice.

I have been thinking about it for a while, i can do it by creating another dependency like spiral/rr-workers but i can't remove this dep from this package until 2.0 as it will be BC.

grachevko commented 5 years ago

@wolfy-j spiral/rr-workers little confuse me, as my client require Worker. I suggested move to another repo only PSR requireded packages and files.

wolfy-j commented 5 years ago

I'll think how to make less damaging dependency split, this is exactly the problem i'm trying to avoid when i'm speaking about https://github.com/spiral/roadrunner/pull/73

Alex-Bond commented 5 years ago

Everyone can implement their own connector bu creating a class that implements IntegrationInterface. If your application requires some advanced integration you always can from original integration and adjust it for yourself, but in how much cases you will change actual psr-worker.php or index.php if you using other servers? My idea mostly covers standardization of community-based integration, so we can tell that they have to just implement our interface and they are ready to go.

You always will need psr/http-message in order to use RR in any generic case. If you have something super specific (which is weird) I would recommend to do not install RR PHP library at all and just create yours from scratch.

wolfy-j commented 5 years ago

You always will need psr/http-message in order to use RR in any generic case. If you have something super specific (which is weird) I would recommend to do not install RR PHP library at all and just create yours from scratch.

Unfortunately it means that custom integration would have to follow protocol implementation as well (including binary marshaling).

Alex-Bond commented 5 years ago

You always will need psr/http-message in order to use RR in any generic case. If you have something super specific (which is weird) I would recommend to do not install RR PHP library at all and just create yours from scratch.

Unfortunately it means that custom integration would have to follow protocol implementation as well (including binary marshaling).

Only if you dont want psr/http-message as a dependency. Otherwise, we will create much more troubles with our own requests and responses.

Alex-Bond commented 5 years ago

I decide that I gonna do this idea as a side library. I will release it after HttpClient will be merged.

Thank both of you for feedback.