Download the PHP package scil/laravel-fly without Composer
On this page you can find all versions of the php package scil/laravel-fly. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download scil/laravel-fly
More information about scil/laravel-fly
Files in scil/laravel-fly
Package laravel-fly
Short Description make laravel faster by using swoole extension.
License MIT
Homepage http://www.github.com/scil/laravel_fly
Informations about the package laravel-fly
Please refer to Swoole handles multiple requests simultaneously per-worker and Hola FrankenPHP! Laravel Octane Servers Comparison
====
Would you like php 7.4 Preloading? Would you like php coroutine? Today you can use them with Laravel because of Swoole. With LaravalFly, Laravel will begin like Django 3.0 to be fully async-capable.
LaravelFly is a safe solution to speeds up new or old Laravel 5.5+ projects, with preloading and coroutine, while without data pollution or memory leak. And it makes Tinker available online (use tinker while Laravel is responding requests from browsers).
Thanks to Laravel, Swoole and PsySh.
Notice: Great News! Laravel is supporting Swoole offcially with laravel/octane!
A simple ab test
ab -k -n 1000 -c 10 http://zc.test
(21 sql statements were executed in single request)
. | fpm | Fly |
---|---|---|
Time taken ≈ | 43.5 s | 12.3 s |
Requests per second | 23 | 81.5 |
50% | 303 ms | 117 ms |
80% | 360 ms | 153 ms |
99% | 1341 ms | 239 ms |
Test Env
Version Compatibility
- Laravel 5.5 ~ 6.0
- Swoole >4.2.13
Quick Start
1.pecl install swoole
Make sure extension=swoole.so
in config file for php cli, not for fpm.
Suggest: pecl install inotify
2.composer require "scil/laravel-fly":"dev-master"
3.php vendor/scil/laravel-fly/bin/fly start
If you enable eval(tinker())
and see an error about mkdir, you can start LaravelFly with sudo.
Now, your project is flying and listening to port 9501. Enjoy yourself.
Docker-compose
Doc
Commands: Start, Reload & Debug
Events about LaravelFly
Using tinker when Laravel Working
For Dev
Recommended Packages
- swlib/saber Coroutine HTTP client, based on
Swoole\Coroutine\Http\Client
.
Browser-like cookie managment, multiple requests concurrent, request/response interceptors and so on.
To ensure safety, setconst LARAVELFLY_COROUTINE = true;
in fly.conf.php.
Features and Behaviors
-
Same codes can run on PHP-FPM or LaravelFly. LaravelFly can be installed on your existing projects without affecting nginx/apache server, that's to say, you can run LaravelFly server and nginx/apache server simultaneously to run the same laravel project. The nginx conf Cooperate with Apache from laravel-s.
-
Moderate strategy: by default, each Third Party service provider is registered on server worker process (before the first request arrived at server) , booted in request.
-
By default, all Laravel official services are COROUTINE-FRIENDLY, including mysql and redis. You can make a service or object before any requests. There are two ways:
- let the service or object live in multiple requests (only one instance of the service). LaravelFly named it WORKER SERVICE, WORKER OBJECT or COROUTINE-FRIENDLY SERVICE/OBJECT.
- cloned the service or object in each request (one instance in one request).LaravelFly named it CLONE SERVICE or CLONE OBJECT. This way is simple, but often has the problem Stale Reference. This type is used widely by laravel-swoole and laravel-s, while used rarely by LaravelFly.
-
Extra speed improvements such as connection pool, middlewares cache, view path cache.
-
Check server info at /laravel-fly/info. (This feture is under dev and more infomations will be available.)
-
No support for static files any more, so use it with other servers. Conf examples: nginx or Apache
-
swoole-job,A Laravel job or event listener can be delivered into a swoole task process and executed at once
artisan queue:work
needless any more. -
exit()
ordie()
in an route action would output content to console or swoole log, and not make server die or reload. If you would like to change that behavior, fork LaravalFly and catch\Swoole\ExitException
inLaravelFly\Map\Kernel::handle
. -
Support connection pool. There's only one connection available in each request.But if you use
fly()
orfly2()
, you can use connections more than one. - functions
fly()
andfly2()
which are likego()
provided by golang or swoole, plus Laravel services can be used infly()
andfly2()
without closure. Thefly2()
has the limited ability to change services in current request, e.g. registering a new event handler for current request.fly2()
is not suggested.
A coroutine starting in a request, can still live when the request ends. What's the effect of following route?
It responds with 'coroutine1; outer1; coroutine2; outer2; outer3',
but it write log 'coroutine1; outer1; coroutine2; outer2; outer3; coroutine2.end; coroutine1.end'
Similar projects that mix swoole and laravel
The main distinguishing feature of LaravalFly is refactoring Laravel, like what Django 3.0 does.
1. laravel-swoole
It is alse a safe sollution. It has supported Lumen and websocket. Its doc is great and also useful for LaravelFly.
The main difference is that in laravel-swoole user's code will be processed by a new app
cloned from SwooleTW\Http\Server\Application::$application and laravel-swoole updates related container bindings to the new app. However in LaravelFly, the sandbox is not a new app, but an item in the $corDict of the unique application container.
In LaravelFly, most other objects such as app
, event
.... always keep one object in a worker process, clone
is not used at all by default. LaravelFly makes most of laravel objects keep safe on their own. It's about high cohesion & low coupling and the granularity is at the level of app container or services/objects. For users of laravel-swoole, it's a big challenge to handle the relations of multiple packages and objects which to be booted before any requests. Read Stale Reference.
. | technique | work to maintaining relations of cloned objects to avoid Stale Reference |
---|---|---|
laravel-swoole | clone app contaniner and objects to make them safe | more work (as app,event...are cloned) |
LaravelFly Mode Map | refactor most official objects to make them safe on their own | few work ( nothing is cloned by default) |
In LaravelFly, another benefit of non-cloned objects is allowing some improvements, such as event listeners cache, route middlewares cache.
2. laravel-s
Many great features!
About data pollution? Same technique and problems as laravel-swoole. And neither support coroutine jumping (from one request to another request).
Todo About Improvement
- [x] Pre-include. Server configs 'pre_include' and 'pre_files'.
- [x] Server config 'early_laravel'
- [x] Cache for LaravelFly app config. laravelfly_ps_map.php or laravelfly_ps_simple.php located bootstrap/cache
- [x] Cache for Log. Server options 'log_cache'.
- [x] Watching maintenance mode using swoole_event_add. No need to check file storage/framework/down in every request.
- [x] Cache for kernel middlewares objects. Kernel::getParsedKernelMiddlewares, only when LARAVELFLY_SERVICES['kernel'] is true.
- [x] Cache for route middlewares. $cacheByRoute in Router::gatherRouteMiddleware, only useful when all route middleaes are reg on worker.
- [x] Cache for route middlewares objects. config('laravelfly.singleton_route_middlewares') and $cacheForObj in Router::gatherRouteMiddleware, avoid creating instances repeatly.
- [x] Cache for terminateMiddleware objects.
- [x] Cache for event listeners. $listenersStalbe in LaravelFly\Map\IlluminateBase\Dispatcher
- [x] Cache for view compiled path. LARAVELFLY_SERVICES['view.finder'] or App config 'view_compile_1'
- [x] Mysql coroutine. Old code dropped, laravel-s used.
- [x] db connection pool and redis connection pool. In
fly()
orfly2()
, connections to be used would be fetched from pool, not inherit the same connections from request coroutine. code:$this->connections[$childId] = [];
in ConnectionsTrait.php - [x] swoole redis driver
- [ ] swoole redis driver: how to use
errMsg
errCode
- [ ] use hyperf/database to replace official version?
- [ ] use swlib/swpdo to replace SwoolePDO?
- [ ] Cache for HasRelationships. disable and experimental, not ready
- [x] Cache for RouteDependencyResolverTrait
- [ ] Converting between swoole request/response and Laravel Request/Response
- [ ] safe: auth, remove some props?
- [ ] use: https://github.com/louislivi/smproxy
- [ ] use: https://github.com/kcloze/swoole-jobs or https://github.com/osgochina/Donkey
Other Todo
- [x] add events
- [x] watch code changes and hot reload
- [x] supply server info. default url is: /laravel-fly/info
- [x] function fly()
- [x] job executed in task process. Related: vendor\scil\laravel-fly-files-local\src\Foundation\Bus\
- [x] event listeners executed in task process. Related: LaravelFly\Map\IlluminateBase\Dispatcher and vendor\scil\laravel-fly-files\src\Foundation\Support\Providers\EventServiceProvider.php
- [ ] use $this->output instead of echo() in Common.php
- [ ] bootstrap all service providers in task process
- [ ] try ocramius/generated-hydrator for laravel-fly/info when its version 3 is ready (it will require nikic/php-parser v4 which is needed by others) // or Zend\Hydrator\Reflection?
- [ ] add tests about auth SessionGuard: Illuminate/Auth/SessionGuard.php with uses Request::createFromGlobals
- [ ] add tests about uploaded file, related symfony/http-foundation files: File/UploadedFile.php and FileBag.php(fixPhpFilesArray)
- [ ] websocket
- [ ] send file
- [ ] travis, static analyze like phan, phpstan or https://github.com/exakat/php-static-analysis-tools
- [ ] cache fly
All versions of laravel-fly with dependencies
laravel/framework Version 5.5.* || 5.6.* || 5.7.* || 5.8.* || 6.0.* || 6.6.*
hhxsv5/laravel-s Version ~2.0
open-smf/connection-pool Version ~1.0
laravel/helpers Version *
ext-swoole Version >=4.2.13
composer/composer Version ^1.8