Download the PHP package glzjin/laravel-s without Composer
On this page you can find all versions of the php package glzjin/laravel-s. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download glzjin/laravel-s
More information about glzjin/laravel-s
Files in glzjin/laravel-s
Package laravel-s
Short Description ? LaravelS: Speed up Laravel/Lumen by Swoole, 'S' means Swoole, Speed, High performance.
License MIT
Homepage https://github.com/hhxsv5/laravel-s
Informations about the package laravel-s
LaravelS - standing on the shoulders of giants
🚀 Speed up Laravel/Lumen by Swoole, 'S' means Swoole, Speed, High performance.
Features
-
High performance Swoole
-
Built-in Http/WebSocket server
-
Memory resident
-
Gracefully reload
-
Automatically reload when code is modified
-
Support Laravel/Lumen, good compatibility
- Simple & Out of the box
Requirements
| Dependency | Requirement |
|---|---|
| PHP | >= 5.5.9 |
| Swoole | >= 1.7.19 The Newer The Better No longer support PHP5 since 2.0.12 |
| Laravel/Lumen | >= 5.1 |
| Gzip[optional] | zlib, be used to compress the HTTP response, check by ldconfig -p|grep libz |
| Inotify[optional] | inotify, be used to reload all worker processes when your code is modified, check by php --ri inotify |
Install
1.Require package via Composer(packagist).
2.Add service provider.
-
Laravel: inconfig/app.phpfile Lumen: inbootstrap/app.phpfile
3.Publish configuration.
Suggest that do publish after upgrade LaravelS every time
Special for Lumen: you DO NOT need to load this configuration manually in bootstrap/app.php file, LaravelS will load it automatically.
4.Change config/laravels.php: listen_ip, listen_port, refer Settings.
Run demo
php artisan laravels {start|stop|restart|reload|publish}
| Command | Description |
|---|---|
start |
Start LaravelS, list the processes by ps -ef|grep laravels |
stop |
Stop LaravelS |
restart |
Restart LaravelS |
reload |
Reload all worker processes(Contain your business & Laravel/Lumen codes), exclude master/manger process |
publish |
Publish configuration file laravels.php into folder config |
Cooperate with Nginx (Recommended)
Cooperate with Apache
Enable WebSocket server
The Listening address of WebSocket Sever is the same as Http Server.
1.Create WebSocket Handler class, and implement interface WebsocketHandlerInterface.
2.Modify config/laravels.php.
3.Use swoole_table to bind FD & UserId, optional, Swoole Table Demo. Also you can use the other global storage services, like Redis/Memcached/MySQL, but be careful that FD will be possible conflicting between multiple Swoole Servers.
4.Cooperate with Nginx (Recommended)
Refer WebSocket Proxy
Listen events
System events
Usually, you can reset/destroy some
global/staticvariables, or change the currentRequest/Responseobject.
-
laravels.received_requestAfter LaravelS parsedswoole_http_requesttoIlluminate\Http\Request, before Laravel's Kernel handles this request. laravels.generated_responseAfter Laravel's Kernel handled the request, before LaravelS parsesIlluminate\Http\Responsetoswoole_http_response.
Customized asynchronous events
This feature depends on
AsyncTaskofSwoole, your need to setswoole.task_worker_numinconfig/laravels.phpfirstly. The performance of asynchronous event processing is influenced by number of Swoole task process, you need to set task_worker_num appropriately.
1.Create event class.
2.Create listener class.
3.Bind event & listeners.
4.Fire event.
Asynchronous task queue
This feature depends on
AsyncTaskofSwoole, your need to setswoole.task_worker_numinconfig/laravels.phpfirstly. The performance of task processing is influenced by number of Swoole task process, you need to set task_worker_num appropriately.
1.Create task class.
2.Deliver task.
Millisecond cron job
Wrapper cron job base on Swoole's Millisecond Timer, replace
LinuxCrontab.
1.Create cron job class.
2.bind cron job.
Get the instance of swoole_server in your project
Use swoole_table
1.Define swoole_table, support multiple.
All defined tables will be created before Swoole starting.
2.Access swoole_table: all table instances will be bound on swoole_server, access by app('swoole')->xxxTable.
Important notices
-
Get all info of request from
Illuminate\Http\RequestObject, compatible with $_SERVER/$_ENV/$_GET/$_POST/$_FILES/$_COOKIE/$_REQUEST,CANNOT USE$_SESSION. -
Respond by
Illuminate\Http\ResponseObject, compatible with echo/vardump()/print_r(),CANNOT USEfunctions like header()/setcookie()/http_response_code(). -
global,staticvariables which you declared are need to destroy(reset) manually. - Infinitely appending element into
static/globalvariable will lead to memory leak.
Known compatible issues
Todo list
-
Connection pool for MySQL/Redis.
- Wrap coroutine clients for MySQL/Redis/Http.

