How to get the current working directory inside Phar?

How can I getcwd() in a PHP script in the Phar archive when called from the console?

Consider this call:

 /path/to/my/actual/cwd> php index.php 

In this case, getcwd() will return /path/to/my/actual/cwd . Now we take the same script, put it in Phar and call it like this:

 /path/to/my/actual/cwd> php /path/to/my/phar/archive.phar 

This time getcwd() will return /path/to/my/phar , since this is the current working directory of the Phar archive, but I did not call the archive from this directory, the cwd console is different.

How can i get this?

Or even better, how can I make all Phar scripts think their cdd is console?

+5
source share
1 answer

Not tested, but I no longer use getcwd () because I am having problems with cronjob. In this case, this was my solution:

 echo __DIR__; 
+1
source

Source: https://habr.com/ru/post/1243330/


All Articles