Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created August 15, 2013 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesleybliss/6245150 to your computer and use it in GitHub Desktop.
Save wesleybliss/6245150 to your computer and use it in GitHub Desktop.
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 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment