PHPackages                             chernegasergiy/battery-info - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chernegasergiy/battery-info

ActivePhp-ext[Utility &amp; Helpers](/categories/utility)

chernegasergiy/battery-info
===========================

Cross-platform PHP extension for retrieving battery level and charging status (Linux, macOS, Windows, Android).

v0.1.0(3mo ago)00LicenseRef-CSSM-Unlimited-2.0CPHP &gt;=8.0CI passing

Since Feb 1Pushed 3mo agoCompare

[ Source](https://github.com/ChernegaSergiy/battery-php-ext)[ Packagist](https://packagist.org/packages/chernegasergiy/battery-info)[ RSS](/packages/chernegasergiy-battery-info/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

battery\_info PHP extension
===========================

[](#battery_info-php-extension)

[![Latest Stable Version](https://camo.githubusercontent.com/1ed1fcbf5466ffce6f776f640be121f75256eac02034872a07ef044688046a43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636865726e6567617365726769792f626174746572792d696e666f2e7376673f6c6162656c3d5061636b6167697374266c6f676f3d7061636b6167697374)](https://packagist.org/packages/chernegasergiy/battery-info)[![Total Downloads](https://camo.githubusercontent.com/6aeb36b96547e38b86c975eef2d9190f415c1a27bd78b3169bb0cfacc32447cc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636865726e6567617365726769792f626174746572792d696e666f2e7376673f6c6162656c3d446f776e6c6f616473266c6f676f3d7061636b6167697374)](https://packagist.org/packages/chernegasergiy/battery-info)[![License](https://camo.githubusercontent.com/c6a61e56c3260bc973b38a71bed2c6982ea73a6658f5d9fb7063ae4603c62916/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636865726e6567617365726769792f626174746572792d696e666f2e7376673f6c6162656c3d4c6963656e6365266c6f676f3d6f70656e2d736f757263652d696e6974696174697665)](https://packagist.org/packages/chernegasergiy/battery-info)[![Build Linux](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-linux.yml/badge.svg)](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-linux.yml)[![Build macOS](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-macos.yml/badge.svg)](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-macos.yml)[![Build Windows](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-windows.yml/badge.svg)](https://github.com/ChernegaSergiy/battery-php-ext/actions/workflows/build-windows.yml)

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 unknown
    - `charging` (bool|null) — true/false or null
    - `status` (string|null) — "charging"/"discharging"/"full"/"not charging"/null
- `level` (int|null) — primary battery level (0..100 or null)
- `charging` (bool|null) — primary battery charging state
- `status` (string|null) — primary battery status
- `platform` (string) — platform name ("linux", "macos", "windows", "android")

Installation
------------

[](#installation)

### Install with PIE (Recommended)

[](#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

[](#manual-installation)

1. **Build or Download** the extension binary for your OS.
2. **Locate your extensions directory**: `php -i | grep extension_dir`.
3. **Copy the file**:
    - Linux/macOS/Android: `battery_info.so`
    - Windows: `php_battery_info.dll`
4. **Enable in `php.ini`**:
    - Add `extension=battery_info` (or `extension=php_battery_info.dll` on Windows).

Build (typical Unix/macOS)
--------------------------

[](#build-typical-unixmacos)

```
phpize
./configure --enable-battery_info
make
sudo make install
```

Usage Example
-------------

[](#usage-example)

```
