Fix CLI mode detection for some shared hosts.

This fixes #690.

[This PHP doc comment](http://www.php.net/manual/en/features.commandline.php#105043) explains the solution in great detail (and very verbose code), so this sounds sensible.