mirror of
https://github.com/kmvan/x-prober.git
synced 2026-08-13 04:31:40 +08:00
显示不正常. 查看源码报错 #75
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @wimotek on GitHub (Feb 16, 2024).
Originally assigned to: @kmvan on GitHub.
<html>-- | Warning: Undefined array key 1 in /www/wwwroot/x.php on line 48
|
| Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /www/wwwroot/x.php on line 48
| | <html lang="en"> </html>
@wimotek commented on GitHub (Feb 16, 2024):
使用的是 php8.2.14
@wimotek commented on GitHub (Feb 16, 2024):
@kmvan commented on GitHub (Feb 16, 2024):
感谢反馈,应该是有某个权限不足导致无法读取某内容然后出现未预料情况就报错了。
试试下载 https://github.com/kmvan/x-prober/blob/dev/dist/prober.php 这个开发版文件,然后看看具体第几行错误再劳烦贴上来?
@rampageX commented on GitHub (Jul 15, 2024):
PHP 8.3.9 也这样。
Line 119:
namespace InnStudio\Prober\Components\Utils; use COM; final class UtilsCpu { public static function getLoadAvg() { if (UtilsApi::isWin()) { return array(0, 0, 0); } return array_map(function ($load) { return (float) sprintf('%.2f', $load); }, sys_getloadavg()); } public static function getModel() { $filePath = '/proc/cpuinfo'; if ( ! @is_readable($filePath)) { return ''; } $content = file_get_contents($filePath); $cores = substr_count($content, 'cache size'); $lines = explode("\n", $content); $modelName = explode(':', $lines[4]); $modelName = trim($modelName[1]); $cacheSize = explode(':', $lines[8]); $cacheSize = trim($cacheSize[1]); return "{$cores} x {$modelName} / " . sprintf('%s cache', $cacheSize); } public static function getWinUsage() { $usage = array( 'idle' => 100, 'user' => 0, 'sys' => 0, 'nice' => 0, ); if (class_exists('COM')) { $wmi = new COM('Winmgmts://'); $server = $wmi->execquery('SELECT LoadPercentage FROM Win32_Processor'); $total = 0; foreach ($server as $cpu) { $total += (int) $cpu->loadpercentage; } $total = (float) $total / \count($server); $usage['idle'] = 100 - $total; $usage['user'] = $total; } else { if ( ! \function_exists('exec')) { return $usage; } $p = array(); exec('wmic cpu get LoadPercentage', $p); if (isset($p[1])) { $percent = (int) $p[1]; $usage['idle'] = 100 - $percent; $usage['user'] = $percent; } } return $usage; } public static function getUsage() { static $cpu = null; if (null !== $cpu) { return $cpu; } if (UtilsApi::isWin()) { $cpu = self::getWinUsage(); return $cpu; } $filePath = '/proc/stat'; if ( ! @is_readable($filePath)) { $cpu = array(); return array( 'user' => 0, 'nice' => 0, 'sys' => 0, 'idle' => 100, ); } $stat1 = file($filePath); sleep(1); $stat2 = file($filePath); $info1 = explode(' ', preg_replace('!cpu +!', '', $stat1[0])); $info2 = explode(' ', preg_replace('!cpu +!', '', $stat2[0])); $dif = array(); $dif['user'] = $info2[0] - $info1[0]; $dif['nice'] = $info2[1] - $info1[1]; $dif['sys'] = $info2[2] - $info1[2]; $dif['idle'] = $info2[3] - $info1[3]; $total = array_sum($dif); $cpu = array(); foreach ($dif as $x => $y) { $cpu[$x] = round($y / $total * 100, 1); } return $cpu; } }@kmvan commented on GitHub (Jul 15, 2024):
看起来像 /proc 目录没权限读取。
@rampageX commented on GitHub (Jul 15, 2024):
照葫芦画瓢写了个简单脚本测试下:
没有报错可以返回结果:
processor : 0 BogoMIPS : 48.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 1 BogoMIPS : 48.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 2 BogoMIPS : 48.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 processor : 3 BogoMIPS : 48.00 Features : fp asimd evtstrm aes pmull sha1 sha2 crc32 cpuid CPU implementer : 0x41 CPU architecture: 8 CPU variant : 0x0 CPU part : 0xd03 CPU revision : 4 cpu 1805321 8 751023 124909923 119641 232127 275807 0 0 0 cpu0 441539 0 195005 31081738 35389 77822 177186 0 0 0 cpu1 458983 3 185822 31275565 28645 50808 30317 0 0 0 cpu2 456386 2 186312 31275151 27852 51544 32249 0 0 0 cpu3 448411 1 183883 31277469 27754 51951 36054 0 0 0 intr 263656777 0 0 0 197815219 0 0 0 0 0 0 0 0 872 5 0 75 0 0 0 0 313770 123787 12684627 185868 0 919 0 0 0 0 0 0 0 0 0 0 632 257 0 0 0 0 4061347 0 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ctxt 436131739 btime 1720696966 processes 146922 procs_running 1 procs_blocked 0 softirq 102474436 0 22573341 81969 23710979 1407316 0 4329847 29231415 128394 21011175@rampageX commented on GitHub (Jul 15, 2024):
这段代码放到 PHP 7.4 / PHP 8.3 两个不同环境测试:
7.4 没事,8.3 第 10 行
$cacheSize = trim($cacheSize[1]);报错。另外,这段代码好像只能针对 x86 的 CPU,我看 ARM 类的
cpuinfo完全不一样。ARM:
@kmvan commented on GitHub (Jul 15, 2024):
https://github.com/kmvan/x-prober/blob/dev/dist/prober.php 试试debug版本,看看具体的错误位置。
@rampageX commented on GitHub (Jul 15, 2024):
好像就是 PHP 8+ 的问题,参考下面:
https://github.com/symfony/symfony/issues/45179#issuecomment-1148229960
按照上面把 trim 那改成类似
trim($v ?? '')就不报错了@kmvan commented on GitHub (Jul 15, 2024):
trim() 函数里面只能是 string 类型,看样子里面的值变成了 null 类型,就报错了。
@rampageX commented on GitHub (Jul 15, 2024):
是啊,你看 ARM CPU 的信息,单核总共才8行,那个
$lines[8]就是 null 了,不过 PHP7 貌似允许,PHP8就不允许了。@kmvan commented on GitHub (Jul 15, 2024):
确实,等候我更新下。
@rampageX commented on GitHub (Jul 15, 2024):
CPU 型号显示那,针对 ARM CPU 估计也得另作处理,缓存没法获取,型号
lscpu是通过 CPU part 数值来查表的:https://github.com/util-linux/util-linux/blob/1c14996da1e132830bcc024c2ca7430fe3c2ac28/sys-utils/lscpu-arm.c#L25-L97
@kmvan commented on GitHub (Jul 16, 2024):
https://github.com/kmvan/x-prober/blob/dev/dist/prober.php 目前开发版会报错吗?如果无报错的话,后续更新应该可以显示具体型号。
@rampageX commented on GitHub (Jul 16, 2024):
不报错了,CPU 显示内容如下:
@kmvan commented on GitHub (Jul 16, 2024):
可以贴一下
lscpu的信息吗?@rampageX commented on GitHub (Jul 16, 2024):
这个是 Phicomm N1:
@rampageX commented on GitHub (Jul 16, 2024):
这个是 Oracle 甲骨文 ARM VPS 的
lscpu信息以及 x-prober dev 版本截图:@kmvan commented on GitHub (Jul 17, 2024):
实际上这个信息里面,可能有用的只有
这两个?你认为还有什么信息有用?在探针里面显示的信息。
@rampageX commented on GitHub (Jul 20, 2024):
Flags 建议显示。
@kmvan commented on GitHub (Jul 22, 2024):
安排。最后可以贴一下 Oracle 那款 vps 的
/proc/cpuinfo信息吗?@rampageX commented on GitHub (Jul 22, 2024):
@kmvan commented on GitHub (Jul 27, 2024):
更新8.18版了