Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the usage examples of TP, batch processing, and scheduled tasks.
Create the entry file E: \ wamp \ www \ ThinkPHP \ System \ Common \ Cron \ WinCron. php required for Batch Processing
if(PHP_SAPI != 'cli') die;
chdir('../../../');
define('WIN_CRON',TRUE);
define('BIND_MODULE','Manage');
define('BIND_CONTROLLER','Cron');
define('APP_MODE','api');
require getcwd().'/index.php';
?>
Create a batch file E: \ wamp \ www \ ThinkPHP \ System \ Common \ Cron \ WinCron. bat
E:
cd E:\wamp\www\ThinkPHP\System\Common\Cron
php.exe WinCron.php
Create Controller E: \ wamp \ www \ ThinkPHP \ System \ Manage \ Controller \ CronController. class. php
Namespace Manage \ Controller;
// Scheduled tasks work with Common/Cron/WinCron. php
Class CronController extends \ Think \ Controller {
Public function _ initialize (){
If (! Defined ('win _ cron') die;
}
Public function index (){
/* Function implementation part */
}
}
Main portal file E: \ wamp \ www \ ThinkPHP \ index. php
If (version_compare (PHP_VERSION, '5. 3.0 ',' <')){
Header ("Content-type: text/html; charset = UTF-8 ");
Die (the 'php environment is not supported. Using this system requires PHP> 5.3.0 ~ ! ');
}
Define ('app _ debug', true); // enable the debugging mode. It is recommended that you enable the annotation of the deployment phase in the development phase or set it to false.
Define ('build _ DIR_SECURE ', false); // automatically generate security directory security files
Define ('app _ name', 'system'); // define the application NAME
Define ('site _ path', str_replace ("\", "/", getcwd (). '/'); // define the website root PATH
Define ('runtime _ path', SITE_PATH. 'runtime/'); // defines the cache directory
Define ('html _ path', SITE_PATH. 'html/'); // defines the static cache directory of the application.
Define ('app _ path', SITE_PATH. 'System/'); // define the project PATH
Define ('common _ path', APP_PATH. 'common/'); // public application directory
Define ('data _ path', COMMON_PATH. 'data/'); // Application DATA Directory
Define ('Think _ path', SITE_PATH. 'core/'); // define the framework system directory
Require THINK_PATH. 'thinkphp. php'; // introduce the Core File
Run WinCron. bat with windows Task Scheduler (scheduled Task ).
If you have any questions, please leave a message. I think it is useful. Please like it.
BY: youyoushan Yu
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB