Download the PHP package php-io-extensions/gpio without Composer
On this page you can find all versions of the php package php-io-extensions/gpio. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package gpio
GPIO
PHP-controllable Linux GPIO extension built with Zephir.
The GPIO extension is an extension for PHP running on supported Linux single-board computers. It allows PHP to use GPIO character devices for sensors, interrupts, LEDs, relays, fans, and similar hardware.
Requirements
- PHP 8.3+ with development headers (
php-dev/php-devel) - FD extension — provides raw integer file descriptors via
Fd\FD::open() - C build toolchain for PHP extensions (
gcc,make,phpize,autoconf) - Supported Linux SBC platforms:
- Raspberry Pi boards running Debian Trixie
- NVIDIA Jetson Orin family boards running JetPack 6
- Linux kernel with GPIO character device support (
/dev/gpiochipN) - GPIO v2 userspace API — kernel 5.10+
Installation
Automatic Installation
PHP PIE is the official PHP extension installer. It builds and enables the extension from the generated C sources in ext/.
Automatic installation requires PIE and the C toolchain for building PHP extensions. Zephir is not required for automatic installation.
Install the FD extension first — GPIO requires raw integer file descriptors that PHP's stream layer cannot provide.
Manual Installation
Manual installation builds the extension from the Zephir source and requires Zephir 0.19+.
Install Zephir if you haven't already:
Use the installer for your target platform:
The installer handles the full workflow: clean → build → copy .so → write 30-gpio.ini into detected conf.d directories → verify php -m → reload php-fpm if present.
To use a specific Zephir binary:
API
All methods are static. File descriptors are plain integers. Use the FD extension to open and close them — PHP's stream-based fopen does not produce the raw integer FDs the kernel ioctls require.
Gpio\GPIOChip
Operations on a GPIO chip file descriptor (e.g. an open /dev/gpiochip0).
getLine(int $fd, int $line, int $flags, int $event_buffer_size = 0, string $consumer = "php-ext-ioctl"): int
Requests a GPIO line and returns a new line file descriptor, or -1 on failure.
| Parameter | Description |
|---|---|
$fd |
Chip file descriptor |
$line |
Line offset on the chip |
$flags |
GPIO_V2_LINE_FLAG_* bitmask (see linux/gpio.h) |
$event_buffer_size |
Kernel-side edge event buffer size; 0 for default |
$consumer |
Label shown in /sys/kernel/debug/gpio |
chipInfo(int $fd): array
Returns chip metadata, or [] on failure.
lineInfo(int $fd, int $offset): array
Returns line metadata, or [] on failure.
lineInfoWatch(int $fd, int $offset): int
Subscribes to line-info change events for $offset on the chip FD. Returns 0 on success, -1 on failure. Read events with lineInfoChanged().
lineInfoUnwatch(int $fd, int $offset): int
Cancels a watch registered with lineInfoWatch(). Returns 0 on success, -1 on failure.
lineInfoChanged(int $fd): array
Blocking read of one gpio_v2_line_info_changed event from the chip FD. Returns [] if no event or on error.
Gpio\GPIOLine
Operations on a line file descriptor returned by GPIOChip::getLine().
getValues(int $fd): int
Returns 1 (HIGH), 0 (LOW), or -1 on failure.
setValues(int $fd, int $value): bool
Drives the line HIGH ($value != 0) or LOW ($value == 0). Returns true on success.
readEdgeEvents(int $fd): array
Blocking read of one edge event from a line configured with EDGE_RISING and/or EDGE_FALLING. Returns [] if no event or on error.
Usage
GPIO v2 flag values for getLine. These map directly to linux/gpio.h — PHP does not define them, so pass the values directly or define your own constants:
| Constant | Value | Description |
|---|---|---|
GPIO_V2_LINE_FLAG_INPUT |
0x04 |
Configure line as input |
GPIO_V2_LINE_FLAG_OUTPUT |
0x08 |
Configure line as output |
GPIO_V2_LINE_FLAG_EDGE_RISING |
0x10 |
Detect rising edges |
GPIO_V2_LINE_FLAG_EDGE_FALLING |
0x20 |
Detect falling edges |
GPIO_V2_LINE_FLAG_BIAS_PULL_UP |
0x100 |
Enable pull-up resistor |
GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN |
0x200 |
Enable pull-down resistor |
Combine with | as needed.
Digital output (LED, relay, fan)
Digital input (button, sensor)
Edge detection (interrupt)
Query chip and line metadata
License
MIT License. See LICENSE.