thinkphp3.2 How to use CLI mode correctly

Source: Internet
Author: User

Recently to use the thinkphp3.2 version of the CLI mode, manual is not a problem, such as php/www/index.php Home/article/get This is not a problem, but the general use of the CLI mode is more scheduled tasks, It's time to write a timed task, like 0 * * * * * php/www/index.php Home/article/get This will lead to the introduction of thinkphp.php failure, this problem is relatively easy to solve, but then there are various other errors, after looking at the relevant core code, finally found no need to modify the code, you can easily use the CLI mode method. The

steps are as follows:
1, the official download of the framework file inside the index.php file to introduce other files using a relative path, which led to the timing of the implementation of the introduction of the thinkphp.php file does not exist, modified to the absolute path.
define (' App_path ', DirName (__file__). ' /application/');
Require dirname (__file__). ' /thinkphp/thinkphp.php ';

2, thinking to go back to the first half step, Just said the relative path of the index.php file with the absolute path problem, but the implementation of the CLI mode, our portal file to be different from the Web service access to the index.php file, such as adding the CLI mode of the entry file cli.php, the content is the same as index.php, and add a word
define (' App_mode ', ' CLI '); The
defines the execution mode of the app. At this point, we have two portal files, one is the Web service access mode index.php, the other is the CLI mode access cli.php
3, in the path/thinkphp/mode below a file, named common.php, copy out, Name it cli.php, and then put the code comment into the log class or delete the
' Think\log ' and Core_path. ' Log '. EXT,

4, delete all caches under the cache--Remember all

5, and then verbose, after the CLI mode call, use the cli.php portal file, such as scheduled task 0 * * * php/www/cli.php home/ Article/get, if it is a Web service access, the index.php file is still used

thinkphp3.2 How to use CLI mode correctly

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.