@@ -73,22 +73,26 @@ public function generateConfig(HeaderInterface $header): void
73
73
$ this ->makePathForFiles ([$ this ->pidFile , $ this ->configFile ]);
74
74
$ this ->touchFile ($ this ->pidFile );
75
75
76
- $ data = $ this ->templates ->render ('nginx_default.conf ' , [
77
- 'serverRoot ' => realpath ($ this ->getServerRoot ()),
78
- 'serverIndex ' => $ this ->configuration ->get ('server.index ' ),
79
- 'serverPort ' => $ this ->configuration ->get ('server.port ' ),
80
- 'serverHost ' => $ this ->configuration ->get ('server.host ' ),
81
- 'prerenderEnabled ' => $ this ->configuration ->get ('server.prerender.enabled ' ),
82
- 'prerenderUrl ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.url ' ),
83
- 'prerenderHeaders ' => $ this ->configuration ->get ('server.prerender.headers ' , []),
84
- 'prerenderResolver ' => $ this ->configuration ->get ('server.prerender.resolver ' , false ),
85
- 'prerenderHost ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.host ' ),
86
- 'headers ' => $ header ->convert ($ this ->configuration ),
87
- 'connProcMethod ' => $ this ->getConnectionProcessingMethod (),
88
- 'pidLocation ' => $ this ->pidFile ,
89
- 'moduleBrotliInstalled ' => $ this ->moduleBrotliInstalled ,
90
- 'platformSupportsAsyncIo ' => $ this ->platformSupportsAsyncIo ,
91
- ]);
76
+ $ data = $ this ->templates ->render (
77
+ 'nginx_default.conf ' ,
78
+ [
79
+ 'serverRoot ' => realpath ($ this ->getServerRoot ()),
80
+ 'serverIndex ' => $ this ->configuration ->get ('server.index ' ),
81
+ 'serverPort ' => $ this ->configuration ->get ('server.port ' ),
82
+ 'serverHost ' => $ this ->configuration ->get ('server.host ' ),
83
+ 'prerenderEnabled ' => $ this ->configuration ->get ('server.prerender.enabled ' ),
84
+ 'prerenderCacheTTL ' => $ this ->configuration ->get ('server.prerender.cache_ttl ' ),
85
+ 'CDNUrl ' => $ this ->getHostWithoutTrailingSlash ('server.prerender.cdn_url ' ),
86
+ 'CDNPath ' => $ this ->configuration ->get ('server.prerender.cdn_path ' ),
87
+ 'prerenderHeaders ' => $ this ->configuration ->get ('server.prerender.headers ' , []),
88
+ 'prerenderResolver ' => $ this ->configuration ->get ('server.prerender.resolver ' , false ),
89
+ 'headers ' => $ header ->convert ($ this ->configuration ),
90
+ 'connProcMethod ' => $ this ->getConnectionProcessingMethod (),
91
+ 'pidLocation ' => $ this ->pidFile ,
92
+ 'moduleBrotliInstalled ' => $ this ->moduleBrotliInstalled ,
93
+ 'platformSupportsAsyncIo ' => $ this ->platformSupportsAsyncIo ,
94
+ ]
95
+ );
92
96
93
97
file_put_contents ($ this ->configFile , $ data );
94
98
}
@@ -103,18 +107,23 @@ public function checkConfig(): void
103
107
*/
104
108
public function start (): void
105
109
{
106
- $ this ->runProcess (['nginx ' , '-c ' , $ this ->configFile ], function () {
107
- $ this ->logger ->info (sprintf (
108
- 'Server started at: %s:%d ' ,
109
- $ this ->configuration ->get ('server.host ' ),
110
- $ this ->configuration ->get ('server.port ' )
111
- ));
112
- });
110
+ $ this ->runProcess (
111
+ ['nginx ' , '-c ' , $ this ->configFile ],
112
+ function () {
113
+ $ this ->logger ->info (
114
+ sprintf (
115
+ 'Server started at: %s:%d ' ,
116
+ $ this ->configuration ->get ('server.host ' ),
117
+ $ this ->configuration ->get ('server.port ' )
118
+ )
119
+ );
120
+ }
121
+ );
113
122
}
114
123
115
124
public function reload (): void
116
125
{
117
- if (! file_exists ($ this ->pidFile )) {
126
+ if ( ! file_exists ($ this ->pidFile )) {
118
127
throw new LogicException ('Can \'t reload server. Pid file not found. ' );
119
128
}
120
129
@@ -136,6 +145,7 @@ public function stop(): void
136
145
137
146
/**
138
147
* @param string $key
148
+ *
139
149
* @return bool|string
140
150
*/
141
151
private function getHostWithoutTrailingSlash (string $ key )
@@ -155,10 +165,10 @@ private function getConnectionProcessingMethod(): string
155
165
{
156
166
switch (PHP_OS_FAMILY ) {
157
167
case 'Linux ' :
158
- return 'epoll ' ;
168
+ return 'epoll ' ;
159
169
case 'Darwin ' :
160
170
case 'BSD ' :
161
- return 'kqueue ' ;
171
+ return 'kqueue ' ;
162
172
default :
163
173
return 'poll ' ;
164
174
}
@@ -169,39 +179,43 @@ private function getConnectionProcessingMethod(): string
169
179
*/
170
180
private function checkIfPrerenderUrlIsAvailable (): void
171
181
{
172
- if (! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
182
+ if ( ! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
173
183
$ this ->logger ->info ('Prerender is not enabled, skip check. ' );
184
+
174
185
return ;
175
186
}
176
187
177
- $ url = $ this ->configuration ->get ('server.prerender.url ' , false );
188
+ $ url = $ this ->configuration ->get ('server.prerender.cdn_url ' , false );
178
189
179
- if (! $ url ) {
180
- throw new InvalidArgumentException ('Prerender URL not set. Check server.prerender.url config key. ' );
190
+ if ( ! $ url ) {
191
+ throw new InvalidArgumentException ('Prerender CDN URL not set. Check server.prerender.cdn_url config key. ' );
181
192
}
182
193
183
194
$ url = (string ) parse_url ($ url , PHP_URL_HOST );
184
195
185
196
if (strlen ($ url ) < 1 ) {
186
- throw new InvalidArgumentException ('Prerender URL is invalid. Check server.prerender.url config key. ' );
197
+ throw new InvalidArgumentException (
198
+ 'Prerender CDN URL is invalid. Check server.prerender.cdn_url config key. '
199
+ );
187
200
}
188
201
189
- $ this ->logger ->info ('Ping prerender url... ' );
202
+ $ this ->logger ->info ('Ping prerender cdn url... ' );
190
203
191
- $ ping = new Ping ($ url );
204
+ $ ping = new Ping ($ url );
192
205
$ latency = $ ping ->ping ('fsockopen ' );
193
206
194
207
if ($ latency !== false ) {
195
- $ this ->logger ->info ('Prerender url is available. ' );
208
+ $ this ->logger ->info ('Prerender cdn url is available. ' );
209
+
196
210
return ;
197
211
}
198
212
199
- $ this ->logger ->warning ('Prerender url could not be reached: ' . $ url );
213
+ $ this ->logger ->warning ('Prerender cdn url could not be reached: ' . $ url );
200
214
}
201
215
202
216
private function checkIfPrerenderHostIsNotEmpty (): void
203
217
{
204
- if (! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
218
+ if ( ! $ this ->configuration ->get ('server.prerender.enabled ' , false )) {
205
219
return ;
206
220
}
207
221
@@ -215,8 +229,10 @@ private function checkIfPrerenderHostIsNotEmpty(): void
215
229
216
230
$ valid = (bool ) parse_url ($ host );
217
231
218
- if (!$ valid ) {
219
- throw new InvalidArgumentException ('Prerender host is invalid (can \'t parse a url). Check server.prerender.host config key. ' );
232
+ if ( ! $ valid ) {
233
+ throw new InvalidArgumentException (
234
+ 'Prerender host is invalid (can \'t parse a url). Check server.prerender.host config key. '
235
+ );
220
236
}
221
237
}
222
238
0 commit comments