背景
使用apereo/phpcas包完成單點登錄,某一次項目中,本地測試沒有問題發(fā)布線上之后cas登錄頁出現(xiàn)Error Internal script failure。
查找原因
看到Error Internal script failure這個錯誤,完全不知道問題出在哪里,各種搜索沒有找到答案,無奈進(jìn)入源碼??吹揭粋€log方法,好像是用來記日志的,判斷的filename存在就記錄日志,繼續(xù)找到看到了setDebug,在setDebug中去設(shè)置了日志文件目錄之后就可以記錄日志了通過日志看具體問題。
public static function log($str)
{
$indent_str = ".";
if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
// Check if file exists and modifiy file permissions to be only
// readable by the webserver
if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
touch(self::$_PHPCAS_DEBUG['filename']);
// Chmod will fail on windows
@chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
}
for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
$indent_str .= '| ';
}
// allow for multiline output with proper identing. Usefull for
// dumping cas answers etc.
$str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
}
}
public static function setDebug($filename = '')
{
if ($filename != false && gettype($filename) != 'string') {
phpCAS :: error('type mismatched for parameter $dbg (should be false or the name of the log file)');
}
if ($filename === false) {
self::$_PHPCAS_DEBUG['filename'] = false;
} else {
if (empty ($filename)) {
if (preg_match('/^Win.*/', getenv('OS'))) {
if (isset ($_ENV['TMP'])) {
$debugDir = $_ENV['TMP'] . '/';
} else {
$debugDir = '';
}
} else {
$debugDir = DEFAULT_DEBUG_DIR;
}
$filename = $debugDir . 'phpCAS.log';
}
if (empty (self::$_PHPCAS_DEBUG['unique_id'])) {
self::$_PHPCAS_DEBUG['unique_id'] = substr(strtoupper(md5(uniqid(''))), 0, 4);
}
self::$_PHPCAS_DEBUG['filename'] = $filename;
self::$_PHPCAS_DEBUG['indent'] = 0;
phpCAS :: trace('START ('.date("Y-m-d H:i:s").') phpCAS-' . PHPCAS_VERSION . ' ******************');
}
}
結(jié)論
終于在日志里看出了問題在寫入session時文件沒有寫入權(quán)限導(dǎo)致cas登錄失敗