PHP timed Tasks

Source: Internet
Author: User

Prior to Java's scheduled tasks, you can configure/etc/crontab to initiate requests under Linux, but this leads to inconsistencies in code management. Individuals are also inclined to use spring's quartz configuration, so that the code is managed together, and the structure and functionality are clearer and more unified. But using the Crontab method, although the manual can also trigger can be very good compensation for some exceptions, but also equals to expose a security risk, the individual think there is room for discretion.

Having said so many off-topic, you can choose your own plan according to the actual choice. Here the main talk about Linux crontab. Incidentally, it is said that it is the preferred scenario to implement timed tasks in PHP.

Crontab file's location:

/etc/crontab

Command:

CD/Etcvim crontab

A hint explaining the configuration can be clearly seen

# Example of Job definition:#.----------------Minute (0- -)# | .-------------Hour (0- at)# |  | .----------Day of Month (1- to)# |  |  | .-------Month (1- A) OR jan,feb,mar,apr ... #|  |  |  | .----Day of Week (0-6) (sunday=0Or7) OR sun,mon,tue,wed,thu,fri,sat#|  |  |  | |# * * * * * * user-name command to be executed

5 parameter time parameters, from left to right, are minutes, hours, days, months, weeks, where (number/*) is performed on behalf of each (number) unit. Example:

#每分钟执行一次的两种实现 # 1 minutes to execute 1 * * * * #每1分钟执行一次 1   * * * * * *

Request once every day 0 o'clock 0.

0 0 * * * Root curl Http:ding.shi.renwu
Or

00"http:ding.shi.renwu"

Here is a reminder, URL pass parameters, cannot use &, because & in Linux under another meaning, with the & connection parameters will cause the parameter loss. There are two ways to resolve this:

1, use escape character,\& instead of &

2,url surrounded by double quotes

Well, it's that simple, configuration done.

To see if a timed task has been executed, you can view it in the log file, where:

/var/log/cron

cd/var/logtail -F cron

This log, only the timed execution, does not show the results returned after the execution.

If you want to see what the request is called, you can use the Curl command to check that the method executes correctly during the debugging phase

" Http:ding.shi.renwu "

This is very different from the direct input request in the browser, like the above mentioned & character problem, the browser input link is not a problem, but the Linux downgrade must be wrong.

And curl can be done with the-D option POST parameters, etc., which are not directly entered by the browser.

Well, the basic configuration and some small pits are introduced here, thank you for browsing! ~

PHP timed Tasks

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.