使用Cron执行CodeIgniter函数


Execute CodeIgniter function using Cron

我必须在ovh平台中设置一个cron-webjob。要调用的脚本将位于php文件"cron.php".中

我需要执行2个代码点火器功能,链接如下:

http://example.com/index.php/process/send1/

http://example.com/index.php/process/send2/

所以我需要在"cron.php"中执行这些链接,你知道如何实现吗?

提前感谢

您不能直接调用codeigniter函数。相反,您可以向每个URL发出一个请求来运行函数代码。您可以使用php-exec函数在它们上运行"wget"命令来发送请求。

在cron.php中:

exec('wget http://example.com/index.php/process/send1/');
exec('wget http://example.com/index.php/process/send2/');

如果由于PHP没有执行该命令的权限而失败,请尝试file_get_contents()或curl。

我用这个方法在我的实时项目中设置了很多cronhttp://www.asim.pk/2009/05/14/creating-and-installing-crontabs-using-codeigniter/