Improved command line support

Uses PHP_SAPI to decide CLI block should run