laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.71k stars 284 forks source link

Request Workerman support #160

Closed Yurunsoft closed 3 years ago

Yurunsoft commented 3 years ago

Workerman is an asynchronous event-driven PHP framework with high performance to build fast and scalable network applications. Workerman supports HTTP, Websocket, SSL and other custom protocols. Workerman supports event extension.

https://github.com/walkor/workerman

barryvdh commented 3 years ago

What is the benefit over Workerman over RoadRunner and Swoole? No binary/extension required? It does support PSR-7 so probably wouldn't be too hard to create; https://github.com/walkor/Workerman/issues/51#issuecomment-684685099 But there is also amphp, php-pm etc

szepeviktor commented 3 years ago

https://github.com/php-pm/php-pm is a very nice project. Will Octane support it?

barryvdh commented 3 years ago

Maybe instead of trying to support them all, we could see if it's possible to add servers with a 3rd party package? I think the most part doesn't need to live in Octane directly, as long as you can add the server somewhere.

barryvdh commented 3 years ago

For reference, I create initial Workerman support. As you can see, I didn't need to change any of the core functions so far, only the ServiceProvider to add bindings (but you can do that 3rd party). Furthermore to actually start it with the octane:start instead of octane:workerman command, we would need to add it as an available server somewhere. https://github.com/laravel/octane/compare/master...barryvdh:workerman?expand=1

(Not this isn't really tested, but it starts Workerman with the octane:workerman --host=0.0.0.0 --port=1234 --workers=4 parameters correctly, it serves Laravel and it shuts down the server. ~I didn't really get it to hot reload yet though (although I think I'm sending the right command~ Edit: fixed). Bit hard to debug further though because I have never used Workerman.

I can PR this but I'll leave it to the Octane team to see what their intention is for other providers.

barryvdh commented 3 years ago

If you abstract it a bit more, at first we could consider moving the start command to the ServerInspector class, just as stop/reload. The state-file is mostly the same for servers like Workerman/Roadrunner/php-pm that have a master process (I guess at least) so maybe there can be 1 common ServerStateFile instead of per driver. If the ServerInspector handles the starting and also the output formatting, there could be a general octane:start-server --server=roadrunner which just uses the registered ServerInspectors to start.

But ofcourse this is just thinking out load. Not sure which drivers there could be more, besides php-pm and Workerman now.

taylorotwell commented 3 years ago

No plans right now. It would primarily depend on how much code it is to maintain and what advantages it would offer against existing drivers.

taylorotwell commented 3 years ago

I think @barryvdh's suggestion of allowing this to be extendable third-party is a good idea.

Salmondx commented 1 year ago

Sorry for "necroposting", but have you guys had time to think how to integrate these third party octane plugins?

Been playing with Workerman for a couple weeks and so far it have been great. Main selling point for it is that it's codebase is pretty "simple", its pure php (just a composer package based on pcntl and optional event extension) and it doesn't require installing any third party extensions that you have to trust (like swoole for example) or require any third party web servers like roadrunner. Another side bonus is that its easy to setup xdebug with it.

It is hard to say about its performance (don't have any production experience with workerman) but based on artificial benchmarks (including some tests with PDO and multiple queries) it performs pretty well: https://www.techempower.com/benchmarks/#section=data-r21&hw=ph&test=fortune Code for such tests is simple (https://github.com/TechEmpower/FrameworkBenchmarks/blob/master/frameworks/PHP/workerman/app.php) and it's hard to predict how it will work on real life apps.

It doesn't provide any cool features like swoole's coroutines but looks like PHP is slowly heading towards native concurrency anyways (recent Fibers RFC as I understand is a foundation for stuff that they plan to do in future).

TLDR; nice option for octane to have, single composer dependency without the need of any external extensions or web servers.

@nunomaduro sorry for a ping but it is such a nice proposal from barryvdh that imho worth reevaluation :smile: