You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 24, 2025. It is now read-only.
This package provides a high performance HTTP server to speed up your laravel/lumen application based on [Swoole](http://www.swoole.com/).
4
8
5
9
## Version Compatibility
6
10
7
11
| PHP | Laravel | Lumen | Swoole |
8
12
|:-------:|:-------:|:-----:|:-------:|
9
13
| >=5.5.9 |~5.1 |~5.1 | >=1.9.3 |
10
14
11
-
## Quick Start
15
+
## Installation
12
16
13
17
Require this package with composer by using the following command:
14
18
15
19
```
16
20
$ composer require swooletw/laravel-swoole
17
21
```
18
22
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
+
19
25
Then, add the service provider:
20
26
21
27
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`:
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
+
37
98
Now, you can run the following command to start the **swoole_http_server**.
38
99
39
100
```
40
101
$ php artisan swoole:http start
41
102
```
42
103
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.
44
107
45
108
```nginx
46
109
server {
@@ -50,7 +113,8 @@ server {
50
113
index index.php;
51
114
52
115
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.
54
118
try_files /not_exists @swoole;
55
119
}
56
120
@@ -60,11 +124,11 @@ server {
60
124
61
125
location @swoole {
62
126
set $suffix "";
63
-
127
+
64
128
if ($uri = /index.php) {
65
129
set $suffix "/";
66
130
}
67
-
131
+
68
132
proxy_set_header Host $host;
69
133
proxy_set_header SERVER_PORT $server_port;
70
134
proxy_set_header REMOTE_ADDR $remote_addr;
@@ -78,15 +142,55 @@ server {
78
142
}
79
143
```
80
144
81
-
## Documentation
145
+
## Performance Reference
146
+
147
+
Test with clean Lumen 5.5, using MacBook Air 13, 2015.
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.
85
185
86
186
## Support
87
187
88
188
Bugs and feature request are tracked on [Github](https://github.com/swooletw/laravel-swoole-http/issues).
89
189
190
+
## Credits
191
+
192
+
The original author of this package: [Huang-Yi](https://github.com/huang-yi)
193
+
90
194
## License
91
195
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