From the command line, I can get the home directory like this:
~/
How can I get the home directory inside my PHP CLI script?
Depends on where you are and what you're trying to do.
$_SERVER is completely unreliable for a non-server script, BUT $_ENV['HOME'] might be better for a standard shell script. You can always print_r( $GLOBALS ) and see what your environment gives you to play with. phpinfo() also spits out plaintxt when called from a CLI script, and just good ole php -i executed from a shell will do the same.