Cron(定時運行守護進程)

出自MoodleDocs
於 2013年8月21日 (三) 03:50 由 Yucheng Hu留言 | 貢獻 所做的修訂
前往:導覽、​搜尋

Moodle 'cron' 守護進程是一個 PHP 的腳本,這個腳本是 Moodle 安裝的一部分,這個進程必須定時在後台運行。

Moodle cron 守護進程腳本運行不同的任務同時被計劃進行內部調度。

重要:不要嘗試忽略在你的 Moodle 站點中設置Cron(定時運行守護進程)。沒有這個守護進程,你的站點將不會完全正常工作。

一個特殊的程序(通常稱為'cron')被用來定時運行 Moodle 腳本。Moodle 的定時運行腳本可以運行發送郵件,更新 Moodle 報表,RSS,完成活動,發布論壇消息和其他任務。因為不同的任務在 Moodle 系統中不是同時運行的,換句話說,這些任務不是同時被觸發的,而是分時被觸發的。

定時任務(運行 Moodle 腳本)是基於 Unix 系統的核心組件,這作業系統包括(Linux 和 OSX)。定時任務使用者管理所有基於時間的服務。在 Widows 中,也有類似的功能,這個功能在 Windows 中被稱為 Windows 任務計劃,這個被設置用來按照時間計劃來運行。

如果你使用的是共享主機服務,你可以諮詢你的服務管理員或者相關文檔來配置定時任務。

實際上,計劃任務包含當個命令行,這個命令行通常設置在系統中的 cron 激活列表中。在基於 Unix 的作業系統中,這個配置文件被配置在'crontab'中。

基本討論

See the later sections for your server type; this section contains some general background information.

There are essentially two steps to implementing cron:

  1. identifying the correct command to run
  2. finding the right place on your system to put the command

Working out the Moodle cron command

Moodle has two different ways to deploy cron which use different scripts within the Moodle install. These are as follows...

  1. The CLI (command line interpreter) script. This will be at the path
    /path/to/moodle/admin/cli/cron.php
    If in doubt, this is the correct script to use. This needs to be run by a 'PHP CLI' program on your computer. So the final command may look something like
    /usr/bin/php /path/to/moodle/admin/cli/cron.php
    You can (and should) try this on your command line to see if it works.
  2. The web based script. This needs to be run from a web browser and will be accessed via a web url something like http://your.moodle.site/admin/cron.php. You can find command line based web browser (e.g. wget) so the final command may look like
    /usr/bin/wget http://your.moodle.site/admin/cron.php
    This has the advantage that it can be run from *anywhere*. If you can't get cron to work on your machine it can be run somewhere else.


Finding the right place to put the command

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: