1
1
# Symfony ReactPHP Server
2
2
3
+ [ ![ CircleCI] ( https://circleci.com/gh/apisearch-io/symfony-react-server.svg?style=svg )] ( https://circleci.com/gh/apisearch-io/symfony-react-server )
4
+ [ ![ Join the Slack] ( https://img.shields.io/badge/join%20us-on%20slack-blue.svg )] ( https://apisearch.slack.com )
5
+
3
6
This package provides an async server for Symfony kernel based on ReactPHP
4
7
packages and Promise implementation. The server is distributed with all the
5
8
Symfony kernel adapters, and can be easily extended for new Kernel
6
9
modifications.
7
10
8
- > At the moment, this server cannot serve static files. This feature will be
9
- > added soon.
10
-
11
11
You can take a look at the
12
12
[ Symfony + ReactPHP Series] ( https://medium.com/@apisearch/symfony-and-reactphp-series-82082167f6fb )
13
13
in order to understand a little bit better the rationale behind using this
14
14
server and Promises in your domain.
15
15
16
+ > This server is mainly designed to work as a non-blocking symfony server. Used
17
+ > as a regular one should be part of an architecture, containing, at least, a
18
+ > balancer and several instanced in several ports. Otherwise you may have
19
+ > performance issues.
20
+
16
21
## Installation
17
22
18
23
In order to use this server, you only have to add the requirement in composer.
@@ -33,7 +38,7 @@ This is a PHP file. This means that the way of starting this server is by, just,
33
38
executing it.
34
39
35
40
``` php
36
- php vendor/bin/server
41
+ php vendor/bin/server 0.0.0.0:8100
37
42
```
38
43
39
44
You will find that the server starts with a default configuration. You can
@@ -43,22 +48,83 @@ configure how the server starts and what adapters use.
43
48
instance in order to start serving Requests. By default, ` symfony4 ` . Can be
44
49
overridden with option ` --adapter ` and the value must be a valid class
45
50
namespace of an instance of ` KernelAdapter `
46
-
51
+
52
+ ``` bash
53
+ php vendor/bin/server 0.0.0.0:8100 --adapter=symfony4
54
+ php vendor/bin/server 0.0.0.0:8100 --adapter=My\O wn\A dapter
55
+ ```
56
+
47
57
- Bootstrap: How the application is bootstrapped. This would be usually a simple
48
58
autoload require, but sometimes, like in symfony, can be some extra actions
49
59
before the Kernel is instanced. By default, ` symfony4 ` . Available options are
50
60
` Symfony4 ` and ` autoload ` . Can be overridden with the option ` --bootstrap ` and
51
61
the value must be a valid path of a file, starting from the project root.
52
-
62
+
63
+ ``` bash
64
+ php vendor/bin/server 0.0.0.0:8100 --bootstrap=symfony4
65
+ php vendor/bin/server 0.0.0.0:8100 --bootstrap=autoload
66
+ php vendor/bin/server 0.0.0.0:8100 --bootstrap=config/myfile.php
67
+ ```
68
+
53
69
- Environment: Kernel environment. By default ` prod ` , but turns ` dev ` if the
54
70
option ` --dev ` is found.
55
-
71
+
72
+ ``` bash
73
+ php vendor/bin/server 0.0.0.0:8100 --dev
74
+ ```
75
+
56
76
- Debug: Kernel will start with this option is enabled. By default false,
57
- enabled if the option ` --debug ` is found.
58
-
77
+ enabled if the option ` --debug ` is found. Makes sense on development
78
+ environment, but is not exclusive.
79
+
80
+ ``` bash
81
+ php vendor/bin/server 0.0.0.0:8100 --dev --debug
82
+ ```
83
+
59
84
- Silent: No information nor any kind of report will be printed in the standard
60
85
output. By default disabled, but can be enabled with ` --silent ` .
61
-
62
- - Non Blocking: This option enabled async kernel. If this option is not found,
63
- the server will use the standard ` handle ` kernel method. Otherwise, will
64
- use the ` handleAsync ` method, working in that case, as a non-blocking server.
86
+
87
+ ``` bash
88
+ php vendor/bin/server 0.0.0.0:8100 --silent
89
+ ```
90
+
91
+
92
+ ## Turning the server non-blocking
93
+
94
+ By default, the server will work as a blocking server with the Symfony HTTP
95
+ Kernel. The server will use the method ` handle ` to properly serve requests. If
96
+ your application starts working with the asynchronous kernel, you must ensure
97
+ your kernel uses the AsyncKernel implementation.
98
+
99
+ > Make sure you have the dependency installed in your composer.json file. You
100
+ > must include the line ` apisearch-io/symfony-async-http-kernel ` under require
101
+ > section. Then, ` composer update ` .
102
+
103
+ To turn on the asynchronous feature, just add this flag
104
+
105
+
106
+ ``` bash
107
+ php vendor/bin/server 0.0.0.0:8100 --non-blocking
108
+ ```
109
+
110
+ ## Serving static files
111
+
112
+ Kernel Adapters have already defined the static folder related to the kernel.
113
+ For example, Symfony4 adapter will provide static files from folder ` /public ` .
114
+
115
+ You can override the static folder with the command option ` --static-folder ` .
116
+ All files inside this defined folder will be served statically in a non-blocking
117
+ way
118
+
119
+ ``` bash
120
+ php vendor/bin/server 0.0.0.0:8100 --static-folder=public
121
+ ```
122
+
123
+ You can disable static folder with the option ` --no-static-folder ` . This can be
124
+ useful when working with the adapter value and want to disable the default
125
+ value, for example, for an API.
126
+
127
+
128
+ ``` bash
129
+ php vendor/bin/server 0.0.0.0:8100 --no-static-folder
130
+ ```
0 commit comments