简体   繁体   English

Linux中的Cron作业,用于运行php文件

[英]Cron job in linux for running php file

I have an php file to create a new text file . 我有一个php文件来创建一个新的文本文件。 That has to run in every minute . 那必须在每一分钟内运行。 I stored that file on /var/www/html/cron.php . 我将该文件存储在/var/www/html/cron.php Also i had done in command prompt 我也已经在命令提示符下完成了

crontab -e

edit the file like 像编辑文件

* * * * * /var/www/html/cron.php

But still cron not working on localhost 但是仍然cron在本地主机上不起作用

you need to specify in the cron the command to execute, ie 您需要在cron中指定要执行的命令,即

[cron time] [command to execute]

/var/www/html/cron.php is not a command just a file, you need to use something like /var/www/html/cron.php不仅仅是命令,而是文件,您需要使用类似

* * * * * php /var/www/html/cron.php 

*better to use full path of php bin instead of php *更好地使用php bin的完整路径而不是php

The command you put in crontab should be something like: 您放入crontab中的命令应类似于:

*/10 * * * *   /usr/bin/php  /var/www/html/cron.php

Where /usr/bin/php is an example path to your php binary. /usr/bin/php是您的php二进制文件的示例路径。

You can find out your php binary with: 您可以使用以下命令找到您的php binary

whereis php

这应该工作:

*/1 * * * * cd /var/www/html;./cron.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM