Heim  >  Artikel  >  php教程  >  linux下实现定时执行php脚本,linux执行php脚本

linux下实现定时执行php脚本,linux执行php脚本

WBOY
WBOYOriginal
2016-06-13 09:14:341066Durchsuche

linux下实现定时执行php脚本,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

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn