system.php
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
class N2SystemHelper
{
public static function testMemoryLimit() {
static $works = null;
if ($works === null) {
$works = true;
if (function_exists('ini_get')) {
$memory_limit = @ini_get('memory_limit');
if (!empty($memory_limit) && $memory_limit != '-1') {
$ok = self::settingToBytes($memory_limit) >= 0x3C00000;
if (!$ok) {
$works = false;
}
}
}
}
return $works;
}
private static function settingToBytes($setting) {
static $short = array(
'k' => 0x400,
'm' => 0x100000,
'g' => 0x40000000
);
$setting = (string)$setting;
if (!($len = strlen($setting))) return NULL;
$last = strtolower($setting[$len - 1]);
$numeric = intval($setting);
$numeric *= isset($short[$last]) ? $short[$last] : 1;
return $numeric;
}
/**
* @param bool $error error message
* @param int $limit
*/
public static function getDebugTrace($error = false, $limit = 5) {
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$outrace = array();
if ($trace) {
foreach ($trace as $k => $trow) {
if ($k > 0 && $k <= ($limit + 1)) {
$outrace[] = $trow;
}
}
}
if ($error) echo "<p><strong>{$error}</strong></p>";
echo N2Html::openTag("pre");
print_r($outrace);
echo N2Html::closeTag("pre");
n2_exit(true);
}
}