PHP 8.5.0 Alpha 4 available for testing

Voting

: nine minus two?
(Example: nine)

The Note You're Voting On

vermicin at antispam dot gmail dot com
20 years ago
If your PHP cli binary is built as a cgi binary (check with php_sapi_name), the cwd functions differently than you might expect.

say you have a script /usr/local/bin/purge
you are in /home/username

php CLI: getcwd() gives you /home/username
php CGI: getcwd() gives you /usr/local/bin

This can trip you up if you're writing command line scripts with php. You can override the CGI behavior by adding -C to the php call:

#!/usr/local/bin/php -Cq

and then getcwd() behaves as it does in the CLI-compiled version.

<< Back to user notes page

To Top