Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 30972b0

Browse files
authored
Merge pull request #1 from swooletw/master
merge readme.md
2 parents 3cf8d82 + f724d83 commit 30972b0

File tree

1 file changed

+114
-10
lines changed

1 file changed

+114
-10
lines changed

README.md

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
# Laravel-Swoole
22

3-
This package provides a high performance HTTP server which based on [Swoole](http://www.swoole.com/).
3+
![php-badge](https://img.shields.io/badge/php-%3E%3D%205.5.9-8892BF.svg)
4+
[![packagist-badge](https://img.shields.io/packagist/v/swooletw/laravel-swoole.svg)](https://packagist.org/packages/swooletw/laravel-swoole)
5+
[![Total Downloads](https://poser.pugx.org/swooletw/laravel-swoole/downloads)](https://packagist.org/packages/swooletw/laravel-swoole)
6+
7+
This package provides a high performance HTTP server to speed up your laravel/lumen application based on [Swoole](http://www.swoole.com/).
48

59
## Version Compatibility
610

711
| PHP | Laravel | Lumen | Swoole |
812
|:-------:|:-------:|:-----:|:-------:|
913
| >=5.5.9 | ~5.1 | ~5.1 | >=1.9.3 |
1014

11-
## Quick Start
15+
## Installation
1216

1317
Require this package with composer by using the following command:
1418

1519
```
1620
$ composer require swooletw/laravel-swoole
1721
```
1822

23+
> This package relies on Swoole. Please make sure your machine has been installed the Swoole extension. Using this command to install quickly: `pecl install swoole`. Visit the [official website](https://wiki.swoole.com/wiki/page/6.html) for more information.
24+
1925
Then, add the service provider:
2026

2127
If you are using Laravel, add the service provider to the providers array in `config/app.php`:
@@ -34,13 +40,70 @@ If you are using Lumen, append the following code to `bootstrap/app.php`:
3440
$app->register(SwooleTW\Http\LumenServiceProvider::class);
3541
```
3642

43+
## Configuration
44+
45+
If you want to change the default configurations, please run the following command to generate a configuration file `http.php` in directory `config/`:
46+
47+
```
48+
$ php artisan vendor:publish
49+
```
50+
51+
`server.host`: The swoole_http_server host.
52+
53+
`server.port`: The swoole_http_server port.
54+
55+
`server.options`: The configurations for `Swoole\Server`. To get more information about swoole server, please read [the official documentation](https://wiki.swoole.com/wiki/page/274.html).
56+
57+
For example, if you want to set the 'max_request':
58+
59+
```php
60+
[
61+
'server' => [
62+
'options' => [
63+
'max_request' => 1000,
64+
],
65+
]
66+
]
67+
```
68+
69+
## Command
70+
71+
> The swoole_http_server can only run in cli environment, and this package provides convenient artisan commands to manage it.
72+
> By default, you can visit your site at http://127.0.0.1:1215
73+
74+
Start the swoole_http_server:
75+
76+
```
77+
$ php artisan swoole:http start
78+
```
79+
80+
Stop the swoole_http_server:
81+
82+
```
83+
$ php artisan swoole:http stop
84+
```
85+
86+
Restart the swoole_http_server:
87+
88+
```
89+
$ php artisan swoole:http restart
90+
```
91+
92+
Reload the swoole_http_server:
93+
94+
```
95+
$ php artisan swoole:http reload
96+
```
97+
3798
Now, you can run the following command to start the **swoole_http_server**.
3899

39100
```
40101
$ php artisan swoole:http start
41102
```
42103

43-
By default, you can visit your site at http://127.0.0.1:1215. And you can also configure domains via nginx proxy:
104+
## Nginx Configuration
105+
106+
> The support of swoole_http_server for Http is not complete. So, you should configure the domains via nginx proxy in your production environment.
44107
45108
```nginx
46109
server {
@@ -50,7 +113,8 @@ server {
50113
index index.php;
51114
52115
location = /index.php {
53-
# Ensure that there is no such file named "not_exists" in your "public" directory.
116+
# Ensure that there is no such file named "not_exists"
117+
# in your "public" directory.
54118
try_files /not_exists @swoole;
55119
}
56120
@@ -60,11 +124,11 @@ server {
60124
61125
location @swoole {
62126
set $suffix "";
63-
127+
64128
if ($uri = /index.php) {
65129
set $suffix "/";
66130
}
67-
131+
68132
proxy_set_header Host $host;
69133
proxy_set_header SERVER_PORT $server_port;
70134
proxy_set_header REMOTE_ADDR $remote_addr;
@@ -78,15 +142,55 @@ server {
78142
}
79143
```
80144

81-
## Documentation
145+
## Performance Reference
146+
147+
Test with clean Lumen 5.5, using MacBook Air 13, 2015.
148+
Benchmarking Tool: [wrk](https://github.com/wg/wrk)
149+
150+
```
151+
wrk -t4 -c100 http://your.app
152+
```
153+
154+
### Nginx with FPM
82155

83-
- [English](docs/english.md)
84-
- [简体中文](docs/chinese.md)
156+
```
157+
Running 10s test @ http://lumen.app:9999
158+
4 threads and 100 connections
159+
Thread Stats Avg Stdev Max +/- Stdev
160+
Latency 1.14s 191.03ms 1.40s 90.31%
161+
Req/Sec 22.65 10.65 50.00 65.31%
162+
815 requests in 10.07s, 223.65KB read
163+
Requests/sec: 80.93
164+
Transfer/sec: 22.21KB
165+
```
166+
167+
### Swoole HTTP Server
168+
169+
```
170+
Running 10s test @ http://127.0.0.1:1215
171+
4 threads and 100 connections
172+
Thread Stats Avg Stdev Max +/- Stdev
173+
Latency 11.58ms 4.74ms 68.73ms 81.63%
174+
Req/Sec 2.19k 357.43 2.90k 69.50%
175+
87879 requests in 10.08s, 15.67MB read
176+
Requests/sec: 8717.00
177+
Transfer/sec: 1.55MB
178+
```
179+
180+
## Notices
181+
182+
1. Please reload or restart the swoole_http_server after released your code. Because the Laravel program will be kept in memory after the swoole_http_server started. That's why the swoole_http_server has high performance.
183+
2. Never use `dd()`, `exit()` or `die()` function to print your debug message. It will terminate your swoole worker unexpectedly.
184+
3. You should have basic knowledge of multi-process programming and swoole. If you still write your code with a single-process conception, your app might have unexpected bugs.
85185

86186
## Support
87187

88188
Bugs and feature request are tracked on [Github](https://github.com/swooletw/laravel-swoole-http/issues).
89189

190+
## Credits
191+
192+
The original author of this package: [Huang-Yi](https://github.com/huang-yi)
193+
90194
## License
91195

92-
The Laravel-Swoole-Http package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
196+
The Laravel-Swoole-Http package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)