Req #70809 [NEW]: Prevent usage of $_SERVER (performance penalty)

From: Date: Thu, 29 Oct 2015 08:41:03 +0000
Subject: Req #70809 [NEW]: Prevent usage of $_SERVER (performance penalty)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-196864@lists.php.net to get a copy of this message
From:             raat1979 at gmail dot com
Operating system: webserver
PHP version:      Next Minor Version
Package:          Apache related
Bug Type:         Feature/Change Request
Bug description:Prevent usage of $_SERVER (performance penalty)

Description:
------------
PHP can be configured to have the $_SERVER variable be created on first
access.
The reason for this is to increase performance.

Unfortunately there is no alternative for many of the $_SERVER values

It's possible to use apache_request_headers() to get the HTTP headers
unfortunately this function does not return the request line.

Other portions of the $_SERVER related to HTTP/hosing variable should
also be covered by functions but the most needy would certainly be the
request line.

Test script:
---------------
It would be of benefit to have a function
apache_request_line($parse=false) that would return the Request line as
send by the client

This would greatly reduce the need of using the $_SERVER variable and
its performance impact.

Another option would be to add an optional argument to
apache_request_headers($requestline=APACHE_REQUEST_NONE) to include the
request line
APACHE_REQUEST_NONE=0  : don't add anything (default/original behavior)
APACHE_REQUEST_LINE=1  : request string on index 0
APACHE_REQUEST_PARTS=2 : request string parts on index 1,2 and 3


Expected result:
----------------
$d= apache_request_line(/* $parse= */ true);
Expected result:

Array('Method'=>'GET',
      'Path'=>'/index.php',
      'Protocol'=>'HTTP/1.1'
     )
====================================================================
$d= apache_request_line(/* $parse = */ $false);
Expected result:
'GET /index.php HTTP/1.1'
====================================================================
$d= apache_request_headers(/* $requestline = */ APACHE_REQUEST_LINE);
Expected result:
Array(0=>'GET /index.php HTTP/1.1',
     'Host'=>'www.example.org'
     ...
     )
====================================================================
$d= apache_request_headers(/* $requestline = */ APACHE_REQUEST_ARRAY);
Expected result:
Array(1=>'GET', 
      2=>'/index.php', 
      3=>'HTTP/1.1',
     'Host'=>'www.example.org'
     ...
     )
====================================================================
$d= apache_request_headers(APACHE_REQUEST_LINE | APACHE_REQUEST_ARRAY);
Expected result:
Array(0=>'GET /index.php HTTP/1.1',
      1=>'GET', 
      2=>'/index.php', 
      3=>'HTTP/1.1',
     'Host'=>'www.example.org'
     ...
     )
====================================================================
$d= apache_request_headers(/* APACHE_REQUEST_NONE */);
Expected result (current implementation):
Array('Host'=>'www.example.org'
     ...
     )
====================================================================

I would not expect any decoding of the URI query of any kind it should
be passed as-is (any decoding can be done with the appropriate functions
manually)
There are plenty of functions that implement this.


Actual result:
--------------
At the moment we need to populate the full $_SERVER variable with a lot
of unneeded stuff just to get the request URI.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=70809&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=70809&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=70809&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=70809&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=70809&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=70809&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=70809&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=70809&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=70809&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=70809&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=70809&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=70809&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=70809&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=70809&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=70809&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=70809&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=70809&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=70809&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=70809&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=70809&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=70809&r=mysqlcfg



Thread (1 message)

  • raat1979 at gmail dot com
« previous php.bugs (#196864) next »