Skip to content

Add missing $_SERVER values #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kentr opened this issue Jan 26, 2016 · 3 comments
Closed

Add missing $_SERVER values #14

kentr opened this issue Jan 26, 2016 · 3 comments

Comments

@kentr
Copy link

kentr commented Jan 26, 2016

Problem/Motivation

Per the PHP docs, some standard $_SERVER values are missing.

There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here. That said, a large number of these variables are accounted for in the » CGI/1.1 specification, so you should be able to expect those.

The CGI spec referenced lists these:

  • 4.1.1. AUTH_TYPE
  • 4.1.2. CONTENT_LENGTH
  • 4.1.3. CONTENT_TYPE
  • 4.1.4. GATEWAY_INTERFACE
  • 4.1.5. PATH_INFO
  • 4.1.6. PATH_TRANSLATED
  • 4.1.7. QUERY_STRING
  • 4.1.8. REMOTE_ADDR
  • 4.1.9. REMOTE_HOST
  • 4.1.10. REMOTE_IDENT
  • 4.1.11. REMOTE_USER
  • 4.1.12. REQUEST_METHOD
  • 4.1.13. SCRIPT_NAME
  • 4.1.14. SERVER_NAME
  • 4.1.15. SERVER_PORT
  • 4.1.16. SERVER_PROTOCOL
  • 4.1.17. SERVER_SOFTWARE

Proposed resolution

Set $request->server parameters correctly, such as in HttpKernel::mapRequest() where the other server parameters are set.

API changes

The interface shouldn't change, but the values available through $request->server->get() should more accurately reflect a standard PHP server environment.

@kentr kentr changed the title Add missing $_SERVER values Add missing $_SERVER values Jan 26, 2016
@kentr
Copy link
Author

kentr commented Jan 26, 2016

Here are some example $_SERVER arrays from my application.

Using standard Nginx + PHP-FPM:

Array
(
    [USER] => www-data
    [HOME] => /var/www
    [FCGI_ROLE] => RESPONDER
    [QUERY_STRING] => keys=similis&foo=bar
    [REQUEST_METHOD] => GET
    [CONTENT_TYPE] =>
    [CONTENT_LENGTH] =>
    [SCRIPT_FILENAME] => /var/www/html/index.php
    [SCRIPT_NAME] => /index.php
    [REQUEST_URI] => /search/node?keys=similis&foo=bar
    [DOCUMENT_URI] => /index.php
    [DOCUMENT_ROOT] => /var/www/html
    [SERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_SOFTWARE] => nginx/1.8.0
    [REMOTE_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 40377
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [SERVER_NAME] => localhost
    [HTTPS] =>
    [REDIRECT_STATUS] => 200
    [PATH_INFO] =>
    [HTTP_HOST] => localhost
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_COOKIE] => testcookie=foobar
    [HTTP_CONNECTION] => keep-alive
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1453817380.6998
    [REQUEST_TIME] => 1453817380
)

Using ReactPHP + PHP-PM (running under PHP-FPM):

Array
(
    [USER] => root
    [HOME] => /root
    [FCGI_ROLE] => RESPONDER
    [REQUEST_METHOD] => GET
    [SCRIPT_NAME] => /index.php
    [SCRIPT_FILENAME] => /var/www/html/start-ppm-php-fpm.php
    [XDG_SESSION_ID] => 2
    [SHELL] => /bin/bash
    [TERM] => xterm-color
    [OLDPWD] => /root
    [LS_COLORS] => rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
    [MAIL] => /var/mail/root
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [PWD] => /var/www/html
    [LANG] => en_US.UTF-8
    [SHLVL] => 1
    [LOGNAME] => root
    [LESSOPEN] => | /usr/bin/lesspipe %s
    [XDG_RUNTIME_DIR] => /run/user/1000
    [LESSCLOSE] => /usr/bin/lesspipe %s %s
    [_] => /usr/bin/cgi-fcgi
    [PHP_SELF] => /index.php
    [REQUEST_TIME_FLOAT] => 1453817162.6808
    [REQUEST_TIME] => 1453817162
)

Missing / different:

These items from the standard PHP-FPM environment are either missing from or slightly different in the PHP-PM environment.

    [QUERY_STRING] => keys=similis&foo=bar
    [CONTENT_TYPE] =>
    [CONTENT_LENGTH] =>
    [SCRIPT_FILENAME] => /var/www/html/index.php
    [REQUEST_URI] => /search/node?keys=similis&foo=bar
    [DOCUMENT_URI] => /index.php
    [DOCUMENT_ROOT] => /var/www/html
    [SERVER_PROTOCOL] => HTTP/1.1
    [GATEWAY_INTERFACE] => CGI/1.1
    [SERVER_SOFTWARE] => nginx/1.8.0
    [SERVER_SOFTWARE] => nginx/1.8.0
    [REMOTE_ADDR] => 127.0.0.1
    [REMOTE_PORT] => 40377
    [SERVER_ADDR] => 127.0.0.1
    [SERVER_PORT] => 80
    [SERVER_NAME] => localhost
    [HTTPS] =>
    [REDIRECT_STATUS] => 200
    [PATH_INFO] =>
    [HTTP_HOST] => localhost
    [HTTP_USER_AGENT] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
    [HTTP_ACCEPT_ENCODING] => gzip, deflate
    [HTTP_COOKIE] => testcookie=foobar
    [HTTP_CONNECTION] => keep-alive

@kentr
Copy link
Author

kentr commented Jan 26, 2016

Looks like the preferred way of manufacturing a synthetic request is with Request::create()

Based on that, I propose changing PHPPM\Bridges\HttpKernel::mapRequest() to use SymfonyRequest::create() instead of new SymfonyRequest().

Results from testing pull request #16:

Before:

###########################
$syRequest->headers->all() =
Array (
  [host] => Array (
    [0] => localhost  
  )
  [x-real-ip] => Array (
    [0] => 127.0.0.1  
  )
  [x-forwarded-for] => Array (
    [0] => 127.0.0.1  
  )
  [connection] => Array (
    [0] => close  
  )
  [user-agent] => Array (
    [0] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0  
  )
  [accept] => Array (
    [0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
  )
  [accept-language] => Array (
    [0] => en-US,en;q=0.5  
  )
  [accept-encoding] => Array (
    [0] => gzip, deflate  
  )
  [cookie] => Array (
    [0] => testcookie=foobar  
  )
)

###########################
$syRequest->server->all() =
Array (
  [REQUEST_METHOD] => GET  
  [REQUEST_URI] => /search/node  
  [SERVER_NAME] => localhost  
)

###########################
$syRequest->getMethod() =
  GET

After:

###########################
$syRequest->headers->all() =
Array (
    [host] => Array (
        [0] => localhost    
    )
    [x-real-ip] => Array (
        [0] => 127.0.0.1    
    )
    [x-forwarded-for] => Array (
        [0] => 127.0.0.1    
    )
    [connection] => Array (
        [0] => close    
    )
    [user-agent] => Array (
        [0] => Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:43.0) Gecko/20100101 Firefox/43.0   
    )
    [accept] => Array (
        [0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
    )
    [accept-language] => Array (
        [0] => en-US,en;q=0.5   
    )
    [accept-encoding] => Array (
        [0] => gzip, deflate    
    )
    [cookie] => Array (
        [0] => testcookie=foobar    
    )
    [cache-control] => Array (
        [0] => max-age=0    
    )
)

###########################
$syRequest->server->all() =
Array (
    [SERVER_NAME] => localhost  
    [SERVER_PORT] => 80 
    [HTTP_HOST] => localhost    
    [HTTP_USER_AGENT] => Symfony/2.X    
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8    
    [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5    
    [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 
    [REMOTE_ADDR] => 127.0.0.1  
    [SCRIPT_NAME] => 
    [SCRIPT_FILENAME] => 
    [SERVER_PROTOCOL] => HTTP/1.1   
    [REQUEST_TIME] => 1453836679    
    [PATH_INFO] => 
    [REQUEST_METHOD] => GET 
    [REQUEST_URI] => /search/node?keys=similis&foo=bar  
    [QUERY_STRING] => keys=similis&foo=bar  
)

###########################
$syRequest->getMethod() =
  GET

@marcj
Copy link
Member

marcj commented Mar 18, 2016

I pushed lately changes that should now fully populate the $_SERVER on each request. Want to check if it is working for you now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants