PHP CLI script starter - useful for quickly setting up command-line scripts.
<?php
// Don't allow PHP to stop after global timeout setting
set_time_limit( 0 );
// Increase memory limit
ini_set( 'memory_limit', '1024M' );
// Remove output buffering
while ( ob_get_level() ) ob_end_clean();
// Output buffers directly
ob_implicit_flush( true );
// Custom error handling
//error_reporting( 0 );
//function handleError( $errno, $errmsg, $filename, $linenum, $vars ) {
// stdError(
// '[' . $errno . '] Line #' . $linenum .
// PHP_EOL . $errmsg . PHP_EOL . ' in ' . $filename
// );
//}
//$old_error_handler = set_error_handler( 'handleError' );
// Only allow this script to be run via the command line
if ( strtoupper(PHP_SAPI) !== 'CLI' ) {
stdError( 'This script can only be run via the command line.', false );
showUsage();
exit( 1 );
}