tonic icon indicating copy to clipboard operation
tonic copied to clipboard

Request URI is incorrect when run under php-fpm/fastcgi

Open frisket opened this issue 10 years ago • 1 comments

When I moved my application from using the standard apache mod-php5 to one run by php-fpm (for performance reasons), I discovered that Tonic subsequently failed to correctly parse the request URI.

The getURIFromEnvironment() in Request.php first looks for $_SERVER['REDIRECT_URL'], and if that exists, uses it for the request URI.

This may be correct when run within apache, but under fpm, it returns the URL to the dispatch script instead.

eg: Original request: http://localhost/myapp/web/category

In Apache: $_SERVER['REDIRECT_URL''] is '/myapp/web/category'

In FPM: $_SERVER['REDIRECT_URL''] is '/myapp/web/dispatch.php'.

I would recommend that Request.php check for $_SERVER["REQUEST_URI"] first instead of $_SERVER["REDIRECT_URL"], as it always seems to contain the correct URI that's needed.

I've hacked around this issue temporarily by overwriting $_SERVER["REDIRECT_URL"] with $_SERVER["REQUEST_URI"] in my dispatch.php, but having this handled in the base code would be great!

frisket avatar Feb 24 '15 17:02 frisket

I've had problems getting the environment order correct to work for all servers, I can't remember how we arrived at the current ordering.

You can pass in the correct request URL when you create the Request object within the dispatcher.

It'd be great if you could add this and test it against mod_php. Ensure that you also update the Request object spec. Let me know if you need some help.

peej avatar Feb 24 '15 21:02 peej