-
Notifications
You must be signed in to change notification settings - Fork 28
Why php-swoole will not used in a Laravel ECO System? #1452
Comments
How would you like to integrate Swoole with the framework itself? |
FTR, there's already https://github.com/swooletw/laravel-swoole What are you asking specifically for? |
@mfn Yes this package is what i need. But why is that not in a core? A mysql and redis driver would be also nice... https://github.com/swoole/swoole-src#mysql |
If it was in the core, everyone using Laravel would have to install the Swoole plugin, which would greatly reduce amount of users using Laravel. |
@approached Because swoole has tradeoff that are not worth the speed bonus in most app. Laravel is fast enough. When you need those, Varnish and caching can do a lot of what's left. And the last 1% can use other options (languages/framework). |
It's not in core because, as it is right now, this is special case/context/circumstance not relevant to the 99% majority of users of Laravel, simple as that. Further, from a software design aspect it would feel wrong to have some specific integration in the framework. The framework is expected to be agnostic and work with mod_php, fpm, react, swoole, etc. If any of those existing adapters have technical problems, I'm sure the authors will come forward and provide specific fixes but as far as I'm concerned that's about as much as integration should happen in my book. |
Official support for swoole would be great. The bad performance of laravel is a weakness. |
@greenlentil: Laravel has bad performance according to whom / to which benchmarks? |
I am using Swoole in production for Laravel and it has been great so far. Before I used to have 4 servers to serve my application and now 2 servers are enough. Here are some of the benefits of using an application server such as Swoole or ReactPHP
The application server is one of the major weaknesses of PHP which Swoole and ReactPHP try to solve. This is not a Laravel problem though. However, these frameworks are taking traction and you can see it from the stars here https://github.com/swoole/swoole-src There is not much needed in Laravel to make it work with those libraries. The scope of a few objects such as User, Session needs to be redefined. |
The only support for Swoole that Laravel need is to make sure not to leak global variables and keep request context separated from libraries. The main problem is not the framework itself though, but also third party code that need to fulfill the same requirement, and that is much harder and without some strong arguments from core php devs it might never happen. |
With the release of php 7.4 coming soon and preloading with a new JIT compiler its probably not even necessary to even consider this as the performance gains from that should reduce load times massively. Taylors already mentioned in a post somewhere he wants to implement the preloading at some point. |
|
This form of preloading is already done by opcache. Swoole, React-php and other similar solutions instead will not only compile the files but run them once. When I check using the debugger I see that every laravel request need ~50ms to boot the framework, and that is the time that will be removed from each request by using those servers and have nothing to do with 7.4 preloading. |
I'm going to be honest: A bunch of Swoole folks have been going to every possible avenue in the community saying "BUT WHAT ABOUT SWOOLE" and then throwing around un-true statements about Laravel's performance. I see some reasonable statements being made in here so I'm going to assume there are super reasonable folks in the Swoole world. If something were to happen in the Swoole-y direction, it would require something like this:
|
Let me try to explain the idea in another way. Whenever a request comes, there are certain steps to process: Opcache, or the preloading coming in PHP 7.4, can help with step 1. The compile only happens at the first request, and it will be cached in the memory for future use. What we are trying to solve by adapting swoole / reactphp / etc. is step 2. We are proposing the idea that allows the framework to boot once and being re-used in all future requests. To make this happens, we need to make sure we are very careful about all global things. otherwise, we may leak memory, or share something expected between requests. This is why changes in core necessary. This is not a small change so before some patches, it's good to hear from the maintainers whether this direction is welcome or not. |
The issue with the whole swoole/reactphp thing is that we may want support, but we need to find a solution, HOW to do it. I was thinking about it, and I believe it is in fact quite simple. Currently container has 2 types of services:
What we need is a new type of service, lets call it "context-based" Implementation would require 3 new methods in container: First method will be used the same way as singelton to simply bind a callback to create your service (partially copied from official docs):
Second method will do 2 things: Last method will be used to remove a stored list of context services from memory and call terminate method on all relevant services (implementing TerminableInterface?). With this implementation its possible to not only split global singletons from ones that are request specific, but also to handle multiple requests by a single process even if request processing will be interlacing (coprocessing?) similar to how nginx works. With this solution all singelton services that are related to current request like What do you guys think? Will this be enough, or did I miss something? |
I like the name and the concept. And it reminds me about GraphQL, they introduced exactly the same concept there for similar reason. |
|
@rhzs I offered a suggestion to Swoole fans to potentially make themselves heard. You're welcome to disagree with me. However, you may find that, if you keep doing the same thing, you're going to keep getting the same result. |
Hi @mattstauffer, I agree with you for being careful integrating certain library, especially into Laravel's core. However, since the 6.x, I don't see huge performance win (difference) in Laravel. My point is not just Swoole, but the Laravel's plan to make 1,000x faster for the upcoming release, regardless the PHP is performing. I've watched and followed Lara conference https://laracon.net/ but there isn't any about benchmark and new tweaking strategy for Laravel that is written in Laravel docs. I know that PHP 8 is coming, but I don't see a lot of performance optimization effort in Laravel core nowadays. CMIIW. |
@rhzs FYI, I'm not the one making the decisions. :) I'm just a random community member sharing opinions. If someone wants to propose adding Swoole, they would do well, IMHO, by writing a proposal like what I suggested above, rather than complaining it's not there or about the current situation. |
@hubertnnn we are in need of the exact same feature even without swoole i called it scoped, but context aware would be the same: #2487 |
PHP is dead |
Laravel Octane is the key. |
Oh well, good job after 1 Year. But currently i now the next big thing. It improve the performance better than ever. |
@maher1337 Actually it seems octane doesn't provide any IOC container request scoped instances. which really is an enormous petty. |
@joelharkes it's still in its early stages more will come. |
It has been added now: |
Hi @ all
Why php-swoole will not used in a Laravel ECO System? Nodejs is very fast and has a event-driven asynchronous way. In php is that not so easy possible with nginx/apache2.
PHP swoole has also a own mysql, redis and worker clients that work Asynchronous. You can improve the performance.
Just check out the benchmark screen.
Package: https://github.com/swoole/swoole-src Benchmark: http://grigorov.website/blog/performance-comparison-php-vs-node-js
Check the use cases: https://www.swoole.co.uk/
The text was updated successfully, but these errors were encountered: