php 如何安装 cron

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1802337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:53:40  来源:igfitidea点击:

How to install cron

phpcron

提问by Rajasekar

I want to run PHP scripts automatically on a schedule. I learned about CRON recently. But I don't know how to install and use it.

我想按计划自动运行 PHP 脚本。我最近了解了 CRON。但是我不知道如何安装和使用它。

I'm using PHP, CSS, HTML, and running on XAMP apache server on localhost. How do I install and use Cron?

我正在使用 PHP、CSS、HTML,并在本地主机上的 XAMP apache 服务器上运行。如何安装和使用 Cron?

回答by TheGrandWazoo

Do you have a Windows machine or a Linux machine?

你有 Windows 机器还是 Linux 机器?

Under Windows cron is called 'Scheduled Tasks'. It's located in the Control Panel. You can set several scripts to run at specified times in the control panel. Use the wizard to define the scheduled times. Be sure that PHP is callable in your PATH.

在 Windows 下,cron 称为“计划任务”。它位于控制面板中。您可以在控制面板中设置多个脚本以在指定时间运行。使用向导定义计划时间。确保 PHP 在您的 PATH 中是可调用的。

Under Linux you can create a crontab for your current user by typing:

在 Linux 下,您可以通过键入以下内容为当前用户创建一个 crontab:

crontab -e [username]

If this command fails, it's likely that cron is not installed. If you use a Debian based system (Debian, Ubuntu), try the following commands first:

如果此命令失败,则可能是未安装 cron。如果您使用基于 Debian 的系统(Debian、Ubuntu),请先尝试以下命令:

sudo apt-get update
sudo apt-get install cron

If the command runs properly, a text editor will appear. Now you can add command lines to the crontab file. To run something every five minutes:

如果命令运行正常,将出现一个文本编辑器。现在您可以将命令行添加到 crontab 文件中。每五分钟运行一次:

*/5 * * * *  /home/user/test.pl

The syntax is basically this:

语法基本上是这样的:

.---------------- minute (0 - 59) 
|  .------------- hour (0 - 23)
|  |  .---------- day of month (1 - 31)
|  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ... 
|  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR sun,mon,tue,wed,thu,fri,sat 
|  |  |  |  |
*  *  *  *  *  command to be executed

Read more about it on the following pages: Wikipedia: crontab

在以下页面阅读更多相关信息:维基百科:crontab

回答by Eric Leschinski

Install cron on Linux/Unix:

在 Linux/Unix 上安装 cron:

apt-get install cron

Use cron on Linux/Unix

在 Linux/Unix 上使用 cron

crontab -e

See the canonical answer about cron for more details: https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

有关更多详细信息,请参阅有关 cron 的规范答案:https: //serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

回答by ???????? ?????????

Installing Crontab on Ubuntu

在 Ubuntu 上安装 Crontab

sudo apt-get update

We download the crontab file to the root

我们将crontab文件下载到root

wget https://pypi.python.org/packages/47/c2/d048cbe358acd693b3ee4b330f79d836fb33b716bfaf888f764ee60aee65/crontab-0.20.tar.gz

Unzip the file crontab-0.20.tar.gz

解压文件 crontab-0.20.tar.gz

tar xvfz crontab-0.20.tar.gz

Login to a folder crontab-0.20

登录文件夹 crontab-0.20

cd crontab-0.20*

Installation order

安装顺序

python setup.py install

See also here:.. http://www.syriatalk.im/crontab.html

另见此处:.. http://www.syriatalk.im/crontab.html

回答by BuvinJ

On CentOS/RHEL:

在 CentOS/RHEL 上:

yum install cronie

回答by user204724

Cron is so named "deamon" (same as service under Win).

Cron 被命名为“deamon”(与 Win 下的服务相同)。

Most likely cron is already installed on your system (if it is a Linux/Unix system).

您的系统上很可能已经安装了 cron(如果它是 Linux/Unix 系统)。

Look here: http://www.comptechdoc.org/os/linux/startupman/linux_sucron.html

看这里:http: //www.comptechdoc.org/os/linux/startupman/linux_sucron.html

or there http://en.wikipedia.org/wiki/Cron

或者那里 http://en.wikipedia.org/wiki/Cron

for more details.

更多细节。