@@ -222,24 +222,29 @@ public function set(String $key, String $value, int $ttl = 0): bool
222222 }
223223 }
224224 $ string = $ ttl . '| ' . $ value ;
225- return file_put_contents ($ filename , $ string, LOCK_EX ) !== false ;
225+ return $ this -> filePutContents ($ filename , $ string ) !== false ;
226226 }
227227
228- private function fileGetContents ( $ path )
228+ private function filePutContents ( $ filename , $ string )
229229 {
230- $ f = fopen ($ path , 'r ' );
231- if ($ f === false ) {
230+ return file_put_contents ($ filename , $ string , LOCK_EX );
231+ }
232+
233+ private function fileGetContents ($ filename )
234+ {
235+ $ file = fopen ($ filename , 'r ' );
236+ if ($ file === false ) {
232237 return false ;
233238 }
234- $ locked = flock ($ f , LOCK_SH );
235- if (!$ locked ) {
236- fclose ($ f );
239+ $ lock = flock ($ file , LOCK_SH );
240+ if (!$ lock ) {
241+ fclose ($ file );
237242 return false ;
238243 }
239- $ data = file_get_contents ($ path );
240- flock ($ f , LOCK_UN );
241- fclose ($ f );
242- return $ data ;
244+ $ string = file_get_contents ($ filename );
245+ flock ($ file , LOCK_UN );
246+ fclose ($ file );
247+ return $ string ;
243248 }
244249
245250 private function getString ($ filename ): String
@@ -4482,14 +4487,16 @@ class Request
44824487 private $ params ;
44834488 private $ body ;
44844489 private $ headers ;
4490+ private $ highPerformance ;
44854491
4486- public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null )
4492+ public function __construct (String $ method = null , String $ path = null , String $ query = null , array $ headers = null , String $ body = null , bool $ highPerformance = true )
44874493 {
44884494 $ this ->parseMethod ($ method );
44894495 $ this ->parsePath ($ path );
44904496 $ this ->parseParams ($ query );
44914497 $ this ->parseHeaders ($ headers );
44924498 $ this ->parseBody ($ body );
4499+ $ this ->highPerformance = $ highPerformance ;
44934500 }
44944501
44954502 private function parseMethod (String $ method = null )
@@ -4534,10 +4541,12 @@ private function parseHeaders(array $headers = null)
45344541 {
45354542 if (!$ headers ) {
45364543 $ headers = array ();
4537- foreach ($ _SERVER as $ name => $ value ) {
4538- if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
4539- $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
4540- $ headers [$ key ] = $ value ;
4544+ if (!$ this ->highPerformance ) {
4545+ foreach ($ _SERVER as $ name => $ value ) {
4546+ if (substr ($ name , 0 , 5 ) == 'HTTP_ ' ) {
4547+ $ key = str_replace (' ' , '- ' , ucwords (strtolower (str_replace ('_ ' , ' ' , substr ($ name , 5 )))));
4548+ $ headers [$ key ] = $ value ;
4549+ }
45414550 }
45424551 }
45434552 }
@@ -4608,6 +4617,12 @@ public function getHeader(String $key): String
46084617 if (isset ($ this ->headers [$ key ])) {
46094618 return $ this ->headers [$ key ];
46104619 }
4620+ if ($ this ->highPerformance ) {
4621+ $ serverKey = 'HTTP_ ' . strtoupper (str_replace ('_ ' , '- ' , $ key ));
4622+ if (isset ($ _SERVER [$ serverKey ])) {
4623+ return $ _SERVER [$ serverKey ];
4624+ }
4625+ }
46114626 return '' ;
46124627 }
46134628
0 commit comments