执行cron命令使用php运行php脚本

时间:2013-11-13 09:56:51

标签: php cron crontab

我花了几个小时来搜索关于使用php的cron执行,但没有任何对我有用...我想每30分钟后执行我的PHP脚本.. 这是myscript.php

<?php
date_default_timezone_set("Asia/Calcutta");
$datetime=date("Y-m-d G.i:s", time());
file_put_contents("aaaaa.txt", "The current time is: $datetime\r\n", FILE_APPEND);
?> 

我用来执行cron命令的脚本是crontest.php

</php
$abc=array();
$dir=dirname(__FILE__);
echo exec("'*/30 * * * * /bin/usr/php $dir/myscript.php' 2>&1", &$abc); 
echo $output;
?>

我尝试了很多不同的命令...... 像..

"'crontab -l */30 * * * * /bin/usr/php $dir/myscript.php' 2>&1"
"'crontab -l */30 * * * * php myscript.php' 2>&1"

但没有任何事情妨碍我。我无法理解我还能做些什么.. 请有人帮忙 在执行crontest.php时,我收到错误“sh:* / 30 * * * * / bin / usr / php /home/content/71/9988871/html/examples/myscript.php:没有这样的文件或目录”

1 个答案:

答案 0 :(得分:0)

尝试按照以下步骤在终端设置cron作业:

1)打开终端

2)运行命令

crontab -e

3)最后添加以下内容

*/30 * * * * /usr/bin/php /path of cron file

这将每30分钟自动运行一次cron文件。