I have a php cli script which is executed from /, but the script lies in /opt/script/script.php. How can I get the dynamic location of the script from within the script
$location = ... (Get the location of the script)
echo $location == '/opt/script' ? 'YAY' : 'Stupid';
Output
YAY
That kind of thing.
dirname(__FILE__)(or__DIR__in newer versions) should be enough. You can find further reference at the Magic Constants chapter.