$ _SERVER root document in CLI

In CLI $_SERVER['DOCUMENT_ROOT'] does not work. How can i fix this? Is there any other option available. I cannot use relative paths because the files are in different directories.

+2
source share
1 answer

$ _ SERVER contains headers that will not be available in the CLI. The web server determines the root of the document. In the CLI you are not using a web server, therefore there is no root document.

You can try to rely on environment variables assuming they are set by your shell.

For example, PWD represents the current directory, and HOME represents the user's home directory.

 $pwd = getenv('PWD'); $home = getenv('HOME'); 

You can also use __FILE__ or __DIR__ magic constants to try to __DIR__ path you are currently on.

+4
source

All Articles