Heim  >  Artikel  >  Backend-Entwicklung  >  Linux下crontab定时执行PHP程序的方法

Linux下crontab定时执行PHP程序的方法

WBOY
WBOYOriginal
2016-07-25 08:59:19966Durchsuche
本文介绍下,在linux系统中,用crontab定时执行php程序的方法。有需要的朋友参考下吧。

在Linux中使用Crontab定时执行PHP的方法,实现步骤如下:

1、使用crontab -e编辑定时任务 内容为:

xx:xx:xx 执行一个hello.php文件

2、php文件必须在文件头一行,加上解释器路径(类似于bash或perl那样)

#!/usr/local/bin/php

注意:PHP的执行需要Apache的支持,shell脚本的执行需要Linux的支持,而Linux支持定时运行某个程序的功能。 然后,直接在/etc/crontab里执行,如如下写法:

*/5 * * * * root /root/hello.php

之前的做法,先是在crontab里执行一个shell程序,然后让shell程序再运行PHP程序,这个其实相当没有效率; 改为直接在/etc/crontab里直接带上php路径,如

*/5 * * * * root php hello.php

,也能正确执行;



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