概要
- インストール失敗や運用がうまくいかなくなった状況を調べる
- システムの設定による形式外のエラー・メッセージを調べる
- boolかintが戻り、負数の場合エラー
- 戻り値-1 組み込み関数function_existsが存在しない
- 戻り値-2 組み込み関数strposもしくはparse_urlが存在しない
- 戻り値-3 上記以外の組み込み関数が存在しない
- 戻り値-4 要求されたメモリ量が少なすぎる
引数
実装
function OX_checkSystemInitialRequirements(&$aErrors){
// Variables for tracking if the test has passed or not,
// and if not, what value to return
$isSystemOK = true;
$return = true;
- 下の7つの関数は、OpenXで使われる関数をチェックするために使うので、別に調べる
// The general list of built in PHP functions that are required to
// run OpenX, apart from the functions:
//
// - "function_exists"
// - "array_intersect"
// - "explode"
// - "ini_get"
// - "trim"
// - "parse_url"
// - "strpos"
//
// These other functions are tested separately, as they are
// required to test for the existence of the functions in the
// array below!
$aRequiredFunctions = array(
'dirname',
'empty',
'file_exists',
'ini_set',
'parse_ini_file',
'version_compare'
);
// Prepare error strings, in the simplest possible way
$errorString1 = 'The built in PHP function "';
$errorString2 = '" is in the "disable_functions" list in your "php.ini" file.';
- function_existsの存在を調べる
- function_existsが存在しない場合、これ以上調べることができないので-1を返す
// Need "function_exists" to be able to test for functions required
// for testing what is in the "disabled_functions" list
if (!function_exists('function_exists')) {
$aErrors[] = $errorString1 . 'function_exists' . $errorString2;
// Cannot detect any more errors, as function_exists is
// needed to detect the required functions!
return -1;
}
// Test for existence of "parse_url" and "strpos", which are
// special cases required for the display of the error message
// in the event of anything failing in this test!
if (!function_exists('parse_url')) {
$aErrors[] = $errorString1 . 'parse_url' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -2;
}
}
if (!function_exists('strpos')) {
$aErrors[] = $errorString1 . 'strpos' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -2;
}
}
- 関数がdisabled_functionsかどうか、下で調べるために使う関数のチェック
// Test for existence of "array_intersect", "explode", "ini_get"
// and "trim", which are all required as part of the code to test
// which functions are in the "disabled_functions" list below...
if (!function_exists('array_intersect')) {
$aErrors[] = $errorString1 . 'array_intersect' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('explode')) {
$aErrors[] = $errorString1 . 'explode' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('ini_get')) {
$aErrors[] = $errorString1 . 'ini_get' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
if (!function_exists('trim')) {
$aErrors[] = $errorString1 . 'trim' . $errorString2;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
- $aRequiredFucntionsの関数が使えるか調べる
// Test the disabled functons list with required functions list
// defined above in $aRequiredFunctions
$aDisabledFunctions = explode(',', ini_get('disable_functions'));
foreach ($aDisabledFunctions as $key => $value) {
$aDisabledFunctions[$key] = trim($value);
}
$aNeededFunctions = array_intersect($aDisabledFunctions, $aRequiredFunctions);
if (count($aNeededFunctions) > 0) {
$isSystemOK = false;
foreach ($aNeededFunctions as $functionName) {
$aErrors[] = $errorString1 . $functionName . $errorString2;
}
}
// Check PHP version, as use of PHP < 5.1.4 will result in parse errors
$errorMessage = "PHP version 5.1.4, or greater, was not detected.";
if (function_exists('version_compare')) {
$result = version_compare(phpversion(), '5.1.4', '<');
if ($result) {
$aErrors[] = $errorMessage;
$isSystemOK = false;
if ($return === true) {
$return = -3;
}
}
}
// Check minimum memory requirements are okay (24MB)
$minimumRequiredMemory = OX_getMinimumRequiredMemory();
$phpMemoryLimit = OX_getMemoryLimitSizeInBytes();
if ($phpMemoryLimit > 0 && $phpMemoryLimit < $minimumRequiredMemory) {
// The memory limit is too low, but can it be increased?
$memoryCanBeSet = OX_checkMemoryCanBeSet();
if (!$memoryCanBeSet) {
$minimumRequiredMemoryInMB = $minimumRequiredMemory / 1048576;
$errorMessage = 'The PHP "memory_limit" value is set to less than the required minimum of ' .
$minimumRequiredMemoryInMB . 'MB, but because the built in PHP function "ini_set" ' .
'has been disabled, the memory limit cannot be automatically increased.';
$aErrors[] = $errorMessage;
$isSystemOK = false;
if ($return === true) {
$return = -4;
}
}
}
- magic_quotes_runtimeを調べ、破棄する
// Check magic_quotes_runtime and try to unset it
$GLOBALS['original_get_magic_quotes_runtime'] = OX_getMagicQuotesRuntime();
if ($GLOBALS['original_get_magic_quotes_runtime']) {
ini_set('magic_quotes_runtime', 0);
if (OX_getMagicQuotesRuntime()) {
// try deprecated set_magic_quotes_runtime
if (function_exists('set_magic_quotes_runtime')) {
@set_magic_quotes_runtime(0);
}
}
// check magic_quotes_runtime again, stop if still is set
if (OX_getMagicQuotesRuntime()) {
$aErrors[] = 'The PHP magic_quotes_runtime option is ON, and cannot be automatically turned off.';
$isSystemOK = false;
if ($return === true) {
$return = -5;
}
}
}
if (!$isSystemOK) {
return $return;
}
return true;
}
コメント