chernegasergiy/battery-info
Composer 安装命令:
pie install chernegasergiy/battery-info
包简介
Cross-platform PHP extension for retrieving battery level and charging status (Linux, macOS, Windows, Android).
README 文档
README
This extension exposes a single function: battery_info() which returns an array with keys:
batteries(array) — array of all detected batteries, each containing:name(string) — battery identifier (e.g., "BAT0", "BAT1")level(int|null) — 0..100 or null if unknowncharging(bool|null) — true/false or nullstatus(string|null) — "charging"/"discharging"/"full"/"not charging"/null
level(int|null) — primary battery level (0..100 or null)charging(bool|null) — primary battery charging statestatus(string|null) — primary battery statusplatform(string) — platform name ("linux", "macos", "windows", "android")
Installation
Install with PIE (Recommended)
The easiest way to install the extension is using PIE (PHP Installer for Extensions):
pie install chernegasergiy/battery-info
Manual Installation
- Build or Download the extension binary for your OS.
- Locate your extensions directory:
php -i | grep extension_dir. - Copy the file:
- Linux/macOS/Android:
battery_info.so - Windows:
php_battery_info.dll
- Linux/macOS/Android:
- Enable in
php.ini:- Add
extension=battery_info(orextension=php_battery_info.dllon Windows).
- Add
Build (typical Unix/macOS)
phpize ./configure --enable-battery_info make sudo make install
Usage Example
<?php if (!function_exists('battery_info')) { die("Extension not loaded"); } $info = battery_info(); echo "Platform: " . $info['platform'] . "\n"; // Check all batteries if (!empty($info['batteries'])) { foreach ($info['batteries'] as $battery) { echo "Battery: " . $battery['name'] . "\n"; echo " Level: " . ($battery['level'] ?? 'unknown') . "%\n"; echo " Status: " . ($battery['status'] ?? 'unknown') . "\n"; } } else { echo "No batteries detected.\n"; } // Or use primary battery info directly if ($info['level'] !== null) { echo "\nPrimary battery: " . $info['level'] . "% (" . $info['status'] . ")\n"; }
Notes
- Android requires a small Java helper class and JNI glue — see
android_battery.ccomments. - On Linux the extension reads
/sys/class/power_supply/*/capacityandstatus. - On macOS the extension uses IOKit (build with Xcode tools available).
- On Windows the extension uses
GetSystemPowerStatus.
Contributing
Contributions are welcome and appreciated! Here's how you can contribute:
- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Please make sure to update tests as appropriate and adhere to the existing coding style.
License
This library is licensed under the CSSM Unlimited License v2.0 (CSSM-ULv2). See the LICENSE file for details.
chernegasergiy/battery-info 适用场景与选型建议
chernegasergiy/battery-info 是一款 基于 C 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「extension」 「android」 「status」 「info」 「battery」 「sysfs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 chernegasergiy/battery-info 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 chernegasergiy/battery-info 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 chernegasergiy/battery-info 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Serves functionality of healthchecks of your application
Doctrine implementation of the MetaborStd (Statemachine) for PHP 8.2+
A custom URL rule class for Yii 2 which allows to create translated URL rules
404 'not found' and 403 'forbidden' error handlers. The 404 handler shows custom content for missing pages but not resources like CSS or JS. The 403 handler redirects to a login URL on unauthorized access.
Provide status and health api endpoints
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 36
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LicenseRef-CSSM-Unlimited-2.0
- 更新时间: 2026-02-01