function cron_example() { if (!inCLI()) { // send headers (for running through web with "Run Manually" link above) if (!headers_sent()) { header("Content-type: text/plain"); header("Content-Disposition: inline; filename='output.txt'"); // Force IE to display as text and not download file ob_disable(); // Turn off browser buffering } // This lines are only needed if your cron script is going to be called directly and you need to enforce security, if cron is added as a CMS "Background Task" then you can specify access rights in: pluginAction_addHandlerAndLink // $CMS_USER = getCurrentUserFromCMS(); // security check for web access - don't show cron filepaths unless logged in // if (!@$CMS_USER['isAdmin']) { die(t("You must be logged in as Admin to run this script from the web!")); } // security check for web access - don't show cron filepaths unless logged in ignore_user_abort(true); // continue running even if user clicks stop on their browser session_write_close(); // v2.51 - End the current session and store session data so locked session data doesn't prevent concurrent access to CMS by user while backup in progress } set_time_limit(0); // ignore PHP's max_execution_time directive // print "My sample Cron \n"; print "--------------------------------------------------------------------------------\n"; // Add your own code here... print "The current time is: " . date('Y-m-d H:i:s') . "\n\n"; print "Done!\n"; // return summary message $summary = "Successful"; if (@$_REQUEST['_pluginAction'] == __FUNCTION__) { exit; } // exit if being run manually from web return $summary; // otherwise, return summary if being run by cron }
// load viewer library chdir(dirname(__FILE__)); // change dir to the directory the script is in (so relative paths below work). require_once 'lib/init.php'; // send headers (for running through web) if (!inCLI()) { header("Content-type: text/plain"); header("Content-Disposition: inline; filename='output.txt'"); // Force IE to display as text and not download file $CMS_USER = getCurrentUserFromCMS(); // security check for web access - don't show cron filepaths unless logged in if (!@$CMS_USER['isAdmin']) { die(t("You must be logged in as Admin to run this script from the web!")); } // security check for web access - don't show cron filepaths unless logged in ob_disable(); // Turn off browser buffering ignore_user_abort(true); // continue running even if user clicks stop on their browser session_write_close(); // v2.51 - End the current session and store session data so locked session data doesn't prevent concurrent access to CMS by user while backup in progress } // ignore PHP's max_execution_time directive set_time_limit(0); // Show cronjob instructions and web warning if (!inCLI()) { $thisScriptPath = __FILE__; $thisScriptUrl = preg_replace("/\\?.*/", '', thisPageUrl()) . '?run=1'; print "CRON WEB INTERFACE WARNING!\n"; print "-------------------------------------------------------------------------------\n"; print "You are currently running cron.php through the web interface. This can be useful\n";