Cron(定时运行守护进程):修订间差异

来自MoodleDocs
跳转至:导航、​搜索
第27行: 第27行:


 下面是相关内容:
 下面是相关内容:
# 命令行脚本:命令行脚本在路径<pre>/path/to/moodle/admin/cli/cron.php</pre>如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:<pre>/usr/bin/php /path/to/moodle/admin/cli/cron.php</pre> 你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
# 命令行脚本:命令行脚本在路径<pre>/path/to/moodle/admin/cli/cron.php</pre>如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:<pre>/usr/bin/php /path/to/moodle/admin/cli/cron.php</pre>你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
# 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:'''http://your.moodle.site/admin/cron.php'''。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:<pre>/usr/bin/wget http://your.moodle.site/admin/cron.php</pre> 这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。
# 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:'''http://your.moodle.site/admin/cron.php'''。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:<pre>/usr/bin/wget http://your.moodle.site/admin/cron.php</pre>这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。


=== 找到放置你定时运行命令行的正确路径 ===
=== 找到放置你定时运行命令行的正确路径 ===

2013年8月24日 (六) 06:33的版本

Moodle 'cron' 守护进程是一个 PHP 的脚本,这个脚本是 Moodle 安装的一部分,这个进程必须定时在后台运行。

Moodle cron 守护进程脚本运行不同的任务同时被计划进行内部调度。

重要:不要尝试忽略在你的 Moodle 站点中设置Cron(定时运行守护进程)。没有这个守护进程,你的站点将不会完全正常工作。

一个特殊的程序(通常称为'cron')被用来定时运行 Moodle 脚本。Moodle 的定时运行脚本可以运行发送邮件,更新 Moodle 报表,RSS,完成活动,发布论坛消息和其他任务。因为不同的任务在 Moodle 系统中不是同时运行的,换句话说,这些任务不是同时被触发的,而是分时被触发的。

定时任务(运行 Moodle 脚本)是基于 Unix 系统的核心组件,这操作系统包括(Linux 和 OSX)。定时任务用户管理所有基于时间的服务。在 Widows 中,也有类似的功能,这个功能在 Windows 中被称为 Windows 任务计划,这个被设置用来按照时间计划来运行。

如果你使用的是共享主机服务,你可以咨询你的服务管理员或者相关文档来配置定时任务。

实际上,计划任务包含当个命令行,这个命令行通常设置在系统中的 cron 激活列表中。在基于 Unix 的操作系统中,这个配置文件被配置在'crontab'中。

基本讨论

针对你使用的操作系统,请对应查看你后面的内容,这部分仅仅讨论一些的基本背景信息。

使用下面 2 步可以对守护进程进行一些有效的配置:

  1. 确定运行的正确命令行
  2. 在你的操作系统中找到正确的位置来存放这个命令

配置 Moodle cron 命令行工作

Moodle 可以使用2 个不同的方法来在你的系统中部署定时运行脚本。

下面是相关内容:

  1. 命令行脚本:命令行脚本在路径
    /path/to/moodle/admin/cli/cron.php
    如果你有所怀疑这个是不是正确的运行脚本。需要在你的系统中运行 'PHP CLI'程序。所以最终的运行脚本如下:
    /usr/bin/php /path/to/moodle/admin/cli/cron.php
    你应该在你的机器上尝试运行这个脚本命令来确定这个命令能正常运行。
  2. 基于 WEB 的脚本。这个命令需要从浏览器上来运行,你需要从浏览器上来访问,访问的地址和下面的的类似:http://your.moodle.site/admin/cron.php。你可以使用一些类似浏览器的命令(例如:wget)。最终的命令如下所示:
    /usr/bin/wget http://your.moodle.site/admin/cron.php
    这种运行方式的好处在于你可以在*任何*地方运行。如果你不能在你的机器上运行计划任务,这个将会是一个非常好的方法。

找到放置你定时运行命令行的正确路径

This really does depend on the system you are using and you should find and read the documentation for your platform or hosting. In most cases getting the Moodle cron to run consists of establishing the correct command (above) and then adding it, and the time to run the command, to some sort of file. This might be either through a specific user interface or by editing the file directly.

If using the CLI version you also need to make sure that the cron process is run as the correct user. This is not an issue with the web version.

Example... installing cron on Ubuntu/Debian Linux. Assuming logged in as root..

use the crontab command to open a crontab editor window for the www-data user. This is the user that Apache (the web server) runs as on Debian based systems

$ crontab -u www-data -e

This will open an editor window. To run the cli cron script every 15 minutes, add the line:

*/15 * * * * /usr/bin/php  /path/to/moodle/admin/cli/cron.php >/dev/null

NOTE: the final >/dev/null sends all the output to the 'bin' and stops you getting an email every 15 minutes.

Setting up cron on your system

Choose the information for your server type:

Here are some more instructions for specific hosts (please check that these are up to date):

Using third party cron service

Besides using cron hosted on your own server, you may use third party cron service (usually called webcron):

  • EasyCron - A webcron service provider that eliminates the need of crontab or other task schedulers to set cron job.

Cron settings in Moodle

There are settings within Moodle that control aspects of cron operation:

Remote cron

Using the 'web based' version of cron it is perfectly ok to place the cron process on a different machine to the Moodle server. For example, the cron service on a Unix server can invoke the cron web 'page' on a Windows based Moodle server.

See also

Using Moodle forum discussions: