Crontab-cron Thinksegmentfault

Source: Internet
Author: User
Keywords php crontab thinkphp
There is a need to be in the background for a long time to execute a PHP script
The thinkphp framework we use
I took a look at the online use of cron
Use cron to request a URL address
Call up the thinkphp action
Feels like it's not particularly reasonable.
If you pass the URL, you'll have Nginx fpm.
Is it possible to directly access PHP files
But if you access PHP files directly
Automatic loading is also a problem
What do the great gods say!

Reply content:

There is a need to be in the background for a long time to execute a PHP script
The thinkphp framework we use
I took a look at the online use of cron
Use cron to request a URL address
Call up the thinkphp action
Feels like it's not particularly reasonable.
If you pass the URL, you'll have Nginx fpm.
Is it possible to directly access PHP files
But if you access PHP files directly
Automatic loading is also a problem
What do the great gods say!

First thinkphp is executed in support of CLI mode, and PHP index.php can be executed directly in the project directory Index/index

Then write a very simple script to run Thinkphp's command line

cli.sh

sh -c "cd /home/wwwroot/think3;php index.php index/index;"

And then crontab-e edit the task, assuming that every minute it executes is

*/1 * * * * /bin/sh /root/cli.sh

The above process is tested and passed under thinkphp3.2.3

Thinkphp also supports CLI mode

  • Related Article

    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.