@@ -135,11 +135,11 @@ public function initMimeTypeMap()
135
135
if (preg_match ("/\s*(\S+)\s+(\S.+)/ " , $ content , $ match ))
136
136
{
137
137
$ mime_type = $ match [1 ];
138
- $ extension_var = $ match [2 ];
139
- $ extension_array = explode (' ' , substr ($ extension_var , 0 , -1 ));
140
- foreach ($ extension_array as $ extension )
138
+ $ workerman_file_extension_var = $ match [2 ];
139
+ $ workerman_file_extension_array = explode (' ' , substr ($ workerman_file_extension_var , 0 , -1 ));
140
+ foreach ($ workerman_file_extension_array as $ workerman_file_extension )
141
141
{
142
- self ::$ mimeTypeMap [$ extension ] = $ mime_type ;
142
+ self ::$ mimeTypeMap [$ workerman_file_extension ] = $ mime_type ;
143
143
}
144
144
}
145
145
}
@@ -151,57 +151,57 @@ public function initMimeTypeMap()
151
151
* @param mixed $data
152
152
* @return void
153
153
*/
154
- public function onMessage ($ connection, $ data )
154
+ public function onMessage ($ connection )
155
155
{
156
156
// REQUEST_URI.
157
- $ url_info = parse_url ($ _SERVER ['REQUEST_URI ' ]);
158
- if (!$ url_info )
157
+ $ workerman_url_info = parse_url ($ _SERVER ['REQUEST_URI ' ]);
158
+ if (!$ workerman_url_info )
159
159
{
160
160
Http::header ('HTTP/1.1 400 Bad Request ' );
161
161
return $ connection ->close ('<h1>400 Bad Request</h1> ' );
162
162
}
163
163
164
- $ path = $ url_info ['path ' ];
164
+ $ workerman_path = $ workerman_url_info ['path ' ];
165
165
166
- $ path_info = pathinfo ($ path );
167
- $ extension = isset ($ path_info ['extension ' ]) ? $ path_info ['extension ' ] : '' ;
168
- if ($ extension === '' )
166
+ $ workerman_path_info = pathinfo ($ workerman_path );
167
+ $ workerman_file_extension = isset ($ workerman_path_info ['extension ' ]) ? $ workerman_path_info ['extension ' ] : '' ;
168
+ if ($ workerman_file_extension === '' )
169
169
{
170
- $ path = ($ len = strlen ($ path )) && $ path [$ len -1 ] === '/ ' ? $ path .'index.php ' : $ path . '/index.php ' ;
171
- $ extension = 'php ' ;
170
+ $ workerman_path = ($ len = strlen ($ workerman_path )) && $ workerman_path [$ len -1 ] === '/ ' ? $ workerman_path .'index.php ' : $ workerman_path . '/index.php ' ;
171
+ $ workerman_file_extension = 'php ' ;
172
172
}
173
173
174
- $ root_dir = isset ($ this ->serverRoot [$ _SERVER ['HTTP_HOST ' ]]) ? $ this ->serverRoot [$ _SERVER ['HTTP_HOST ' ]] : current ($ this ->serverRoot );
174
+ $ workerman_root_dir = isset ($ this ->serverRoot [$ _SERVER ['HTTP_HOST ' ]]) ? $ this ->serverRoot [$ _SERVER ['HTTP_HOST ' ]] : current ($ this ->serverRoot );
175
175
176
- $ file = "$ root_dir / $ path " ;
176
+ $ workerman_file = "$ workerman_root_dir / $ workerman_path " ;
177
177
178
- if ($ extension === 'php ' && !is_file ($ file ))
178
+ if ($ workerman_file_extension === 'php ' && !is_file ($ workerman_file ))
179
179
{
180
- $ file = "$ root_dir /index.php " ;
181
- if (!is_file ($ file ))
180
+ $ workerman_file = "$ workerman_root_dir /index.php " ;
181
+ if (!is_file ($ workerman_file ))
182
182
{
183
- $ file = "$ root_dir /index.html " ;
184
- $ extension = 'html ' ;
183
+ $ workerman_file = "$ workerman_root_dir /index.html " ;
184
+ $ workerman_file_extension = 'html ' ;
185
185
}
186
186
}
187
187
188
188
// File exsits.
189
- if (is_file ($ file ))
189
+ if (is_file ($ workerman_file ))
190
190
{
191
191
// Security check.
192
- if ((!($ request_realpath = realpath ($ file )) || !($ root_dir_realpath = realpath ($ root_dir ))) || 0 !== strpos ($ request_realpath , $ root_dir_realpath ))
192
+ if ((!($ workerman_request_realpath = realpath ($ workerman_file )) || !($ workerman_root_dir_realpath = realpath ($ workerman_root_dir ))) || 0 !== strpos ($ workerman_request_realpath , $ workerman_root_dir_realpath ))
193
193
{
194
194
Http::header ('HTTP/1.1 400 Bad Request ' );
195
195
return $ connection ->close ('<h1>400 Bad Request</h1> ' );
196
196
}
197
197
198
- $ file = realpath ($ file );
198
+ $ workerman_file = realpath ($ workerman_file );
199
199
200
200
// Request php file.
201
- if ($ extension === 'php ' )
201
+ if ($ workerman_file_extension === 'php ' )
202
202
{
203
- $ cwd = getcwd ();
204
- chdir ($ root_dir );
203
+ $ workerman_cwd = getcwd ();
204
+ chdir ($ workerman_root_dir );
205
205
ini_set ('display_errors ' , 'off ' );
206
206
ob_start ();
207
207
// Try to include php file.
@@ -210,7 +210,7 @@ public function onMessage($connection, $data)
210
210
// $_SERVER.
211
211
$ _SERVER ['REMOTE_ADDR ' ] = $ connection ->getRemoteIp ();
212
212
$ _SERVER ['REMOTE_PORT ' ] = $ connection ->getRemotePort ();
213
- include $ file ;
213
+ include $ workerman_file ;
214
214
}
215
215
catch (\Exception $ e )
216
216
{
@@ -223,22 +223,22 @@ public function onMessage($connection, $data)
223
223
$ content = ob_get_clean ();
224
224
ini_set ('display_errors ' , 'on ' );
225
225
$ connection ->close ($ content );
226
- chdir ($ cwd );
226
+ chdir ($ workerman_cwd );
227
227
return ;
228
228
}
229
229
230
230
// Static resource file request.
231
- if (isset (self ::$ mimeTypeMap [$ extension ]))
231
+ if (isset (self ::$ mimeTypeMap [$ workerman_file_extension ]))
232
232
{
233
- Http::header ('Content-Type: ' . self ::$ mimeTypeMap [$ extension ]);
233
+ Http::header ('Content-Type: ' . self ::$ mimeTypeMap [$ workerman_file_extension ]);
234
234
}
235
235
else
236
236
{
237
237
Http::header ('Content-Type: ' . self ::$ defaultMimeType );
238
238
}
239
239
240
240
// Get file stat.
241
- $ info = stat ($ file );
241
+ $ info = stat ($ workerman_file );
242
242
243
243
$ modified_time = $ info ? date ('D, d M Y H:i:s ' , $ info ['mtime ' ]) . ' GMT ' : '' ;
244
244
@@ -259,7 +259,7 @@ public function onMessage($connection, $data)
259
259
Http::header ("Last-Modified: $ modified_time " );
260
260
}
261
261
// Send to client.
262
- return $ connection ->close (file_get_contents ($ file ));
262
+ return $ connection ->close (file_get_contents ($ workerman_file ));
263
263
}
264
264
else
265
265
{
0 commit comments