Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/247.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php codeigniter中的Cron作业_Php_Codeigniter_Cron_Cpanel - Fatal编程技术网

Php codeigniter中的Cron作业

Php codeigniter中的Cron作业,php,codeigniter,cron,cpanel,Php,Codeigniter,Cron,Cpanel,我正在尝试用一个内置CodeIgniter的站点做一个cron工作——我已经可以访问CPanel cron功能了,有人能推荐使用CPanel设置cron工作的最佳方法吗 我正在使用CodIgniter,因此无法确定如何在cron作业中调用控制器 例如http://admin.com/sites/publish/ 如何使用cron作业在站点控制器中访问此发布功能 最好的方法是从cron作业中的命令行调用 php /path/to/index.php controller >> /dev

我正在尝试用一个内置CodeIgniter的站点做一个cron工作——我已经可以访问CPanel cron功能了,有人能推荐使用CPanel设置cron工作的最佳方法吗

我正在使用CodIgniter,因此无法确定如何在cron作业中调用控制器

例如
http://admin.com/sites/publish/


如何使用cron作业在站点控制器中访问此发布功能

最好的方法是从cron作业中的命令行调用

php /path/to/index.php controller >> /dev/null

您可以通过CI中的命令行运行控制器,请参阅。

对于我来说,更简单的方法是使用cURL并在cron中执行url:

curl http://admin.com/sites/publish/
如果您需要保护url,可以使用以下方式通过post发送数据:

curl -X POST -d "apikey=yourapikey&another=variable" http://admin.com/sites/publish/
这样,您就不必与php参数和不同的配置作斗争。

我这样做, 创建文件夹cron

/application
/cron
   my_task.php
/public
使用内容为每个cron作业/cron/my_task.php创建脚本

<?  $_SERVER["SCRIPT_URL"] = "/controllerName/MethodName"; // you can set url in routes if you want
    $_SERVER["HTTP_HOST"] = "your_site_address.com"; // without http://www
    require(dirname(__FILE__) . "/../public/index.php");  // path to index.php
 ?>  

对于Cronjob,请尝试访问命令行控制器、函数和参数:

php index.php/controller/function/param1/param2/param3 etc


只需使用这个命令并粘贴它

wget www.example.com/index.php/controller/function

你认为这对我的目的正确吗?php/home/username/public_html/index.php/sites/publish>/dev/null+1,但我将根据问题和您使用的路径添加
php/path/to/index.php sites publish>/dev/null
(意识到您刚刚给出了一个我想澄清的示例)您好-刚刚尝试,cron正在运行,但是我收到了下面的cron守护进程消息。注意:控制器名为sites&函数名为cron/bin/sh:/home/username/public_html/index.php/sites/publish:不是目录否您的命令错误应该是
/home/username/public_html/index.php sites publish
在index.php之后,您将控制器作为参数发送。我在您的命令中没有看到指向php的路径,此外,您还可以尝试将参数放在引号中,例如….
php/home/username/public\u html/index.php“sites publish”
使用此选项,您可以向全世界公开您的cron作业。您可以使用htpasswd保护它们。我知道使用php比使用curl更安全,但是对于一些愚蠢的东西来说,这种方法更简单。
php index.php controller function param1 param2 param3 etc
wget www.example.com/index.php/controller/function