【发布时间】:2012-05-08 09:03:44
【问题描述】:
我有一个 cron 任务设置来运行以下内容:
php /var/www/vhosts/examplesite.com/index.php cron processCategoryItemCount
当我在我的生产服务器(通过 MediaTemple dv4 托管)上运行此程序时,ssh 窗口上会闪烁以下错误:
您的系统文件夹路径似乎设置不正确。请 打开以下文件并更正:index.php
当我在我的开发 mac 上运行 php CLI 命令时,我根本没有收到任何错误。
据我所知,我的 system_path 设置正确.. 这是 sn-p。
/*
*---------------------------------------------------------------
* SYSTEM FOLDER NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" folder.
* Include the path if the folder is not in the same directory
* as this file.
*
*/
$system_path = 'system';
手动测试
我做了一些测试来检查 CI 用来确定 system_path 和 application_path 的代码。据我所知,它工作正常..
CodeIgniter 使用以下代码进行路径验证
// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (realpath($system_path) !== FALSE)
{
$system_path = realpath($system_path).'/';
}
// ensure there's a trailing slash
$system_path = rtrim($system_path, '/').'/';
// Is the system path correct?
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}
因此,我制作了一个 test.php 文件并将其粘贴到我的 httproot..
<?php
$system_path = 'system';
echo "index.php dir is: ".dirname(__FILE__)."\n";
chdir(dirname(__FILE__));
echo "System Dir is: ".realpath($system_path)."\n";
if ( ! is_dir($system_path)){
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}else{
echo "System Path Set Properly\n";
}
sleep(30);
我用这个命令通过命令行运行这个:
/usr/bin/php /var/www/vhosts/examplesite.com/client/stage/test.php`
这是我得到的回报:
index.php dir is: /var/www/vhosts/examplesite.com/client/stage
System Dir is: /var/www/vhosts/examplesite.com/client/stage/system
System Path Set Properly
所以,再进行一些测试,我发现问题出在这部分:
if ( ! is_dir($system_path))
{
exit("Your system folder path does not appear to be set correctly. Please open the following file and correct this: ".pathinfo(__FILE__, PATHINFO_BASENAME));
}
【问题讨论】:
-
如果您通过浏览器运行 cron 文件,是否会出现该错误?
-
不,它没有,如果我设置了一个安全的控制器来运行它不会吓坏的任务。仅适用于 CLI 和 cron 任务。
-
那么,如果您使用 wget shell 命令来运行您的 cron 作业,这应该可以解决问题,因为它基本上就像有人通过浏览器访问该页面。
-
我很欣赏您的评论,但我更愿意解决问题而不是绕过它。
-
好的,但我不明白,“cron”是你的控制器之一,还是命令?你试过写一个“|”在 index.php 和 cron 之间?还是在第一种情况下是“/”?
标签: php codeigniter cron