-
Notifications
You must be signed in to change notification settings - Fork 390
1. Introduction
Swoole is a production-grade async programming framework for PHP. It is a PHP extension written in pure C language, which enables PHP developers to write high-performance, scalable, concurrent TCP, UDP, Unix socket, HTTP, Websocket services in PHP programming language without too much knowledge about non-blocking I/O programming and low-level Linux kernel. You can imagine Swoole is something like NodeJS but for PHP, with higher performance.
Swoole is widely used in many large enterprises in China, such as Baidu, Tencent, Camera 360 and so on. Swoole 2.0 even supports Couroutine, Swoole Coroutine is similar to Coroutine in the other lanaguge or frameworks. Swoole creates one coroutine for each reqeust and schedule based on IO status.
Images below illustrate the lifecycle in PHP. As you can see, when you run php script every time, PHP needs to initialize modules and launch Zend Engine for your running environment. And your PHP script needs to be compiled to OpCodes and then Zend Engine can finally execute them.
However, this lifecycle needs to go over and over in each request. Because the environment created for single request will be immediately destroyed after the request is over.
In other words, in traditional lifecycle, PHP wastes a bunch of time building and destroying resources for your scipt execution. And imagine in frameworks like Laravel, how many files do you need to load in one request? There's a lot I/O consumption for loading files as well.
So what if we have a build in server on top of PHP, and all the scripts can be kept in memory after the first load? This is why we try to run Laravel on Swoole. Swoole can be a powerful performance acceletator and Laravel provides the elegant structure and code usages. That's a perfect combination!
Nevertheless, to be honest, this is not an easy job to integrate Swoole with Laravel. Laravel itself is not designed for structures like Swoole. And there are may be slightly changes in the internal code every time Laravel releases a new version. This package takes a lot of efforts trying to be compatible for Laravel and Lumen above version 5.1. But not able to guarantee if it is 100% compatible.