crontab wget command timed Execution thinkphp controller Implementation Timing task

Source: Internet
Author: User
Tags php script

Background: The project needs to configure a scheduled task to scan the data table data, will be expiring orders marked out, write to the System message reminder table. Previously configured Crontab to execute PHP scripts directly, and then all the way to the process to achieve the end of the business. Recent projects have used the thinkphp framework, thinking that the framework for data manipulation encapsulation convenience, do not want to run the PHP script file alone. However, the controller controller file written in the project, configured to crontab new after the call to the corresponding method is completely ineffective. Toss some time, found not finished, on the resolute give up, think of Linux command wget. It is possible to start configuring wget and setting the address to the address of the controller to be executed. However, it is important to remember that the controller of a task running is best to inherit a base class, and then write the validation section in the thinkphp initial function _initialize of the base class, so as to avoid external access as much as possible ( You can verify that the Access IP is username and pwd in the local or access address.

Above is the description of the business, the following directly on the code

* * * * * root wget-t 1-t 0-q--spider "Http://localhost/tptest/index.php?c=timetask&a=get_sys_warm&visit_name =123456&visit_pwd=123456 "
There are several parameters for the wget command:

-T: Number of connections (reconnection after failure)

-T: Connection time settings (0 does not timeout)

-Q: Quiet mode (no message output)

--spider: Do not download any information

Note: A bit of a problem is that this belongs to the Web form, although in the Access controller has IP and secret key verification, but not sure if there are any security risks.

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.