在项目中使用到windows的定时任务来执行php,但是发现配合ci,却找不到方法来传递uri参数,手动$_SERVER["REQUEST_URI"]可以浏览器中正常运行.但是放到cmd下面的php.exe来运行时,却发现参数在另一个数组中.简单的方法就是改uri的获取方式了.加上cmd的情况下的提取
-------------
在命令行中调用
>php.exe cmd.php
-------
cmd.php
虽然设置了
$_SERVER["REQUEST_URI"] = 'home/email/queue/' .$maxLetters. '/' .$sleep;
但是在cmd php.exe中调试打印出$_SERVER,竟然无此参数,参数自动跑到argc的数组下面去.
没办法只能改core中的代码了.
--------
<?php
$maxLetters = 10;//运行一次发送件数
$sleep = 20; //如果相同dns暂停秒后再发送,可以设置0,然后启用smtp中的间隔时间
$_SERVER["REQUEST_URI"] = 'home/email/queue/' .$maxLetters. '/' .$sleep;
phpinfo();
include('index.php');
----------
修改core/uri.php中的
增加
empty($uri) && isset($_SERVER["argc"]) && (!empty($_SERVER["argc"]['REQUEST_URI'])) && ($uri = $_SERVER["argc"]['REQUEST_URI']);//qidizi增加,让cmd php.exe也支持此参数
/**
* Get the URI String
*
* @access private
* @return string
*/
function _fetch_uri_string()
{
if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
{
// Is the request coming from the command line?
if (defined('STDIN'))
{
$this->_set_uri_string($this->_parse_cli_args());
return;
}
// Let's try the REQUEST_URI first, this will work in most situations
if ($uri = $this->_detect_uri())
{
$this->_set_uri_string($uri);
return;
}
// Is there a PATH_INFO variable?
// Note: some servers seem to have trouble with getenv() so we'll test it two ways
$path = (isset($_SERVER['PATH_INFO'])) ? $_SERVER['PATH_INFO'] : @getenv('PATH_INFO');
if (trim($path, '/') != '' && $path != "/".SELF)
{
$this->_set_uri_string($path);
return;
}
// No PATH_INFO?... What about QUERY_STRING?
$path = (isset($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : @getenv('QUERY_STRING');
if (trim($path, '/') != '')
{
$this->_set_uri_string($path);
return;
}
// As a last ditch effort lets try using the $_GET array
if (is_array($_GET) && count($_GET) == 1 && trim(key($_GET), '/') != '')
{
$this->_set_uri_string(key($_GET));
return;
}
// We've exhausted all our options...
$this->uri_string = '';
return;
}
$uri = strtoupper($this->config->item('uri_protocol'));
if ($uri == 'REQUEST_URI')
{
$uri = $this->_detect_uri();
empty($uri) && isset($_SERVER["argc"]) && (!empty($_SERVER["argc"]['REQUEST_URI'])) && ($uri = $_SERVER["argc"]['REQUEST_URI']);//qidizi增加,让cmd php.exe也支持此参数
$this->_set_uri_string($uri);
return;
}
elseif ($uri == 'CLI')
{
$this->_set_uri_string($this->_parse_cli_args());
return;
}
$path = (isset($_SERVER[$uri])) ? $_SERVER[$uri] : @getenv($uri);
$this->_set_uri_string($path);
}