Baldinof / roadrunner-bundle

A RoadRunner worker integrated in your Symfony app
MIT License
266 stars 47 forks source link

$_SERVER['DOCUMENT_ROOT'] is empty #88

Closed asterd closed 1 year ago

asterd commented 2 years ago

Hi,

I have this issue: I've replaced the nginx/php-fpm configuration to use rr. The problem is that the $_SERVER['DOCUMENT_ROOT'] variable is always empty. I've also tried to define them in the server section of the .rr.yaml but without success

server: command: "php public/index.php" env:

The TEST variable is visible, the DOCUMENT_ROOT remains empty. What I have to do? Thanks a lot!

Baldinof commented 2 years ago

Hello!

This seems to be a PHP behavior:

$ DOCUMENT_ROOT=hello php -r 'var_dump($_SERVER["DOCUMENT_ROOT"]);'
string(0) ""

It seems ok with getenv():

DOCUMENT_ROOT=hello php -r 'var_dump(getenv("DOCUMENT_ROOT"));'
string(5) "hello"

You can either use another variable name or use getenv(), I'm affraid you cannot workaround it without touching the code.

asterd commented 2 years ago

unfortunately not. I've tried to use getenv("DOCUMENT_ROOT") and it returns false (I'm using a symfony controller and I've tried - for testing purpose - to print out all the $_SERVER configurations and also the getenv("DOCUMENT_ROOT") but in both cases, the result is empty (or false))... Where I have to define the document_root variable? in .rr.yaml it doesn't work.. it seem to be overridden by something. If I try to print the TEST variable, it comes out correctly, and also if I call the variable DOCUMENT_ROOTS.. Any suggestion?

Baldinof commented 2 years ago

I also got false with getenv() the first time but finally it's working. Did you clear the cache?

Declaring in .rr.yaml or .rr.dev.yaml (if you are launching in dev mode) should work, but you can also directly prefix the command.

$ env DOCUMENT_ROOT=hello bin/rr serve -c .rr.dev.yaml

$ curl http://localhost:8080/test
{"docroot":"hello"}