Home > php教程 > php手册 > body text

linux下实现定时执行php脚本

WBOY
Release: 2016-06-06 20:10:37
Original
1141 people have browsed it

这篇文章主要介绍了linux下实现定时执行php脚本的方法及具体使用示例,非常不错的文章,这里推荐给大家。

在linux中输入命令

复制代码 代码如下:


crontab -e

然后使用vim的命令编辑打开的文件,输入

复制代码 代码如下:


0 * * * * /usr/bin/php -f /home/userxxx/update.php

保存,退出,好了,现在系统会在每个0点自动执行update.php脚本,脚本中可以编写数据库执行,自动发邮件等功能。

注:直接写成 0 * * * * php -f /home/userxxx/update.php将不会起作用。

 另外cronjob的格式为:

MIN HOUR DOM MON DOW CMD

Field Description Allowed Value

MIN Minute field 0 to 59

HOUR Hour field 0 to 23

DOM Day of Month 1-31

MON Month field 1-12

DOW Day Of Week 0-6(0表示星期天)

CMD Command Any command to be executed.

使用(-)可以划定范围

 如:0 0-6 * * * command 表示每天0-6点整执行command

使用(,)可以枚举时间

 如: 0,15,30,45 * * * * command 表示每个小时的0分,15分,45分,,30分会执行command

使用(/)可以指定间隔

 如:* */4 * * * command表示每四小时执行command

组合用法

0-10/2 * * * * command表示在前10分钟内每隔2分钟执行command

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!