1

我几乎成功地在我的服务器上设置了一个 Cron 作业,但我无法调用正确的控制器。

工作:

  */15 * * * * php fullpath/index.php cron  

结果:我得到了默认控制器的 HTML 输出,而不是我的 Cron 控制器。

工作:

  */15 * * * * php fullpath/index.php cron index  

结果:我得到了默认控制器的 HTML 输出,而不是我的 Cron 控制器。

有人可以请教我做错了什么吗?

注意:我不想使用wgetcurl

4

1 回答 1

0

创建 index.php 的副本,并将其命名为 cli.php。

在 cli.php 开头添加

#!/usr/local/bin/php
<?php

/* we don't need to be limited by...normal limitations */
set_time_limit(0);
ini_set('memory_limit', '256M');

/* make sure this isn't being called by a web browser */
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');

/* set some constants */
define('CMD', 1);

/* manually set the URI path based on command line arguments... */
unset($argv[0]); /* ...but not the first one */
$_SERVER['QUERY_STRING'] =  $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = '/' . implode('/', $argv) . '/';

然后将您的 cron 更改为调用 cli.php 而不是 index.php。

于 2013-04-10T08:06:58.437 回答