Moodle Cron问题解决过程回顾

本文详细介绍了 Moodle 中 Cron 服务的作用与设置方法。Cron 作为 Moodle 的心跳,负责定期执行任务,如检查讨论区并发送邮件。文章解释了如何在 Linux 服务器上通过 crontab 命令配置 cron.php 脚本自动运行,包括使用 wget 工具每 5 或 30 分钟调用一次。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

什么是Cron?

Some of Moodle's modules require continual checks to perform tasks. For example, Moodle needs to check the discussion forums so it can mail out copies of posts to people who have subscribed. 

The script that does all this is located in the admin directory, and is called cron.php. However, it can not run itself, so you need to set up a mechanism where this script is run regularly (eg every five or ten minutes). This provides a "heartbeat" so that the script can perform functions at periods defined by each module. This kind of regular mechanism is known as a cron service. 

Note that the machine performing the cron does not need to be the same machine that is running Moodle.For example,if you have a limited web hosting service that does not have a cron service,then you might choose to run cron on another server or on your home computer.All that matters is that the cron.php file is called regularly. 



n       如何使Cron,php自动运行?

远程登录(或直接登录)基于Linux系统的服务器进行一些命令操作就可以了。

All that Cpanel does is provide a web interface to a Unix utility known as crontab. If you have a command line, you can set up crontab yourself using the command: 

crontab –e

说明:the "crontab -e" command will put you into the 'vi' editor.

这里的example.com是Moodle网址。服务器上应安装wget。

and then adding one of the above commands like: 

*/30 * * * * wget -q -O /dev/null http://example.com/moodle/admin/cron.php

说明: 

如果需要5分钟运行一次,只要把“30”改为“5”就可以了。

The first five entries are the times to run values, followed by the command to run. The asterisk is a wildard, indicating any time. The above example means run the command wget -q -O /dev/null... every 30 minutes (*/30), every hour (*), every day of the month (*), every month (*), every day of the week (*). 

The "O" of "-O" is the capital letter not zero, and refers the output file destination, in this case "/dev/null" which is a black hole and discards the output. If you want to see the output of your cron.php then enter its url in your browser. 

For beginners, "EDITOR=nano crontab -e" will allow you to edit the crontab using the nano editor. Ubuntu defaults to using the nano editor. 

You enter "insert mode" by pressing "i", then type in the line as above, then exit insert mode by pressing ESC. You save and exit by typing ":wq", or quit without saving using ":q!" (without the quotes). Here is an intro to the 'vi' editor. 

转载于:https://www.cnblogs.com/laipDIDI/articles/2141353.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值