TP + batch processing + scheduled task _ simple instance _ Welcome to axe Zheng

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.