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.