是否有办法用Cron Job加载一个页面?

时间:2022-06-14 05:59:31

I have created a php file; so every time I run that, it will run copy all the database to a folder inside my host.

我创建了一个php文件;每次运行时,它都会将所有数据库复制到主机内的文件夹中。

So I was wondering is there a way to call a cron job to load that page every day ?

所以我想知道是否有一种方法可以让cron job每天加载那个页面?

3 个解决方案

#1


1  

Yes, create a shell script say, myscript.sh, that calls this php, for example:

是的,创建一个shell脚本,比如myscript。sh,它调用这个php,例如:

#!/bin/sh
php yourscript.php

and then schedule it in cron to run (for example) every 6 hours:

然后把它安排在cron(例如)每6小时运行一次:

0 */6 * * * ./myscript.sh

#2


2  

Yes you can.

是的,你可以。

Do a sudo crontab -e and you can add this line:

做一个sudo crontab -e,你可以添加以下内容:

0 0 * * * /path/to/php /path/to/php/file.php

Basically what this means is that everyday at midnight, it will run the command by invoking the php interpreter, and then running your php file.

这基本上意味着,每天午夜,它将通过调用php解释器运行命令,然后运行php文件。

Make sure your php file has the correct permissions for root (or for whatever user you'd like to run the cronjob under).

确保您的php文件具有root(或您希望在下面运行cronjob的任何用户)的正确权限。

Edit: If you're using cPanel, check out this documentation: http://docs.cpanel.net/twiki/bin/view/11_30/CpanelDocs/CronJobs#Adding a cron job

编辑:如果您正在使用cPanel,请查看以下文档:http://docs.cpanel.net/twiki/binki/view/11_30 / cpaneldocs/cronjobs #添加cron作业

#3


0  

It depends on what you mean by 'view'. You can certainly set up a cron job that runs PHP cURL, or shell commands (wget, curl, etc.), but it won't be loaded in a browser.

这取决于你所说的“观点”是什么意思。您当然可以设置运行PHP cURL或shell命令(wget、cURL等)的cron作业,但不会在浏览器中加载。

#1


1  

Yes, create a shell script say, myscript.sh, that calls this php, for example:

是的,创建一个shell脚本,比如myscript。sh,它调用这个php,例如:

#!/bin/sh
php yourscript.php

and then schedule it in cron to run (for example) every 6 hours:

然后把它安排在cron(例如)每6小时运行一次:

0 */6 * * * ./myscript.sh

#2


2  

Yes you can.

是的,你可以。

Do a sudo crontab -e and you can add this line:

做一个sudo crontab -e,你可以添加以下内容:

0 0 * * * /path/to/php /path/to/php/file.php

Basically what this means is that everyday at midnight, it will run the command by invoking the php interpreter, and then running your php file.

这基本上意味着,每天午夜,它将通过调用php解释器运行命令,然后运行php文件。

Make sure your php file has the correct permissions for root (or for whatever user you'd like to run the cronjob under).

确保您的php文件具有root(或您希望在下面运行cronjob的任何用户)的正确权限。

Edit: If you're using cPanel, check out this documentation: http://docs.cpanel.net/twiki/bin/view/11_30/CpanelDocs/CronJobs#Adding a cron job

编辑:如果您正在使用cPanel,请查看以下文档:http://docs.cpanel.net/twiki/binki/view/11_30 / cpaneldocs/cronjobs #添加cron作业

#3


0  

It depends on what you mean by 'view'. You can certainly set up a cron job that runs PHP cURL, or shell commands (wget, curl, etc.), but it won't be loaded in a browser.

这取决于你所说的“观点”是什么意思。您当然可以设置运行PHP cURL或shell命令(wget、cURL等)的cron作业,但不会在浏览器中加载。