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