PHPackages                             calcinai/phpi - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. calcinai/phpi

ActiveLibrary[HTTP &amp; Networking](/categories/http)

calcinai/phpi
=============

Event driven bindings for the Raspberry Pi GPIO

v0.3.3(8y ago)97674[1 PRs](https://github.com/calcinai/phpi/pulls)1MITPHP &gt;=5.4.0

Since Jun 17Compare

[ Source](https://github.com/calcinai/phpi)[ Packagist](https://packagist.org/packages/calcinai/phpi)[ RSS](/packages/calcinai-phpi/feed)WikiDiscussions Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (16)Used By (1)

PHPi
====

[](#phpi)

[![Build Status](https://camo.githubusercontent.com/b004c6f77cba77c3b4af0b002a01e7fbe16ffb2154f69573410dcf3e44f9c754/68747470733a2f2f7472617669732d63692e6f72672f63616c63696e61692f706870692e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/calcinai/phpi)[![Latest Stable Version](https://camo.githubusercontent.com/e5e59e661acfea5fdca18b90e117c05c335840684ada07542af502c32b741dd6/68747470733a2f2f706f7365722e707567782e6f72672f63616c63696e61692f706870692f762f737461626c65)](https://packagist.org/packages/calcinai/phpi)

Event driven bindings for the Raspberry Pi GPIO. Supports A, A+, B, Brev2, B+, 2B, 3B, Compute Module and Pi Zero.

This library interacts (almost) directly with the peripheral registers for maximum functionality and speed. See note on `mmap/dma`

> As there is no ability to `mmap` in PHP, by default, this has been delegated to a python subprocess. The python has been kept to an absolute minimum (&lt;25 lines) in terms of complexity to allow flexibility at PHP level.

> **This means that you MUST have python installed alongside PHP for it to function.** *…sortof*

> There is also a [native PHP extension](https://github.com/calcinai/php-ext-mmap) that is a drop-in replacement for the python subprocess which greatly improves performance. I'd strongly recommend using it, especially with less powerful Pis.

This library will function without any kernel drivers/sysfs etc enabled.

Setup
-----

[](#setup)

Using composer:

```
composer require calcinai/phpi

```

Although it is possible to add this to your own autoloader, it's not recommended as you'll have no control of the dependencies. If you haven't used composer before, I strongly recommend you check it out at

Usage
-----

[](#usage)

All of this code is designed to be run in cli mode, as root to permit the memory access. It is not recommended to try and run this in a synchronous nature (namely under apache/nginx) as this would introduce stability and security issues. See below for more information about webservices.

You can test your install and get a visual display of the pin states by running `./bin/phpi info` from the install directory.

The board factory:

```
$board = \Calcinai\PHPi\Factory::create();
```

Minimal example of reading and setting a pin

```
use Calcinai\PHPi\Pin\PinFunction;
use Calcinai\PHPi\Pin;

$pin = $board->getPin(17) //BCM pin number
             ->setFunction(PinFunction::INPUT)
             ->setPull(Pin::PULL_UP);

//Will be === to Pin::LEVEL_HIGH or Pin::LEVEL_LOW
var_dump($pin->getLevel());

$pin->setFunction(PinFunction::OUTPUT);
$pin->high();
$pin->low();
```

Higher level devices and events

```
$button = new Button($board->getPin(17));
$led = new LED($board->getPin(18));

$button->on('press', [$led, 'on']);
$button->on('release', [$led, 'off']);

$board->getLoop()->run();
```

### GPIO

[](#gpio)

GPIO (input) is the default mode of the pin objects. Alternate functions can be accessed by using the `->setFunction(PinFunction::x)` method. It is recommended to use the function names as opposed to `ALT0..5` unless you know exactly what you're doing, as quite a lot are reserved. A few useful classes are also included for digital interaction. With the default python-mmap, you can expect a raw transition speed of ~20kHz, with the native extension, it's more like 80kHz on a Pi 3.

### PWM

[](#pwm)

Hardware PWM is supported by this library, and to an extent, so is soft PWM. As this code runs in the react event loop, it's not practical to interact with the ports more than a few hundred times/sec.

### SPI

[](#spi)

SPI is supported along with some device protocols (MPC300x etc). With the default python-mmap, it is limited to about 3kB/s before there is no CPU left! With the native extension, you can reach speeds of over 30kB/s.

### The event loop

[](#the-event-loop)

One of the original reasons for basing this project on the [react event loop](https://github.com/reactphp/event-loop) was for the other components that can be leveraged. A good example is the websocket server; it will run seamlessly inline with this library to provide *real time, bidirectional, non-polling* interaction with the Pi from any modern browser.

See [phpi-websocket](https://github.com/calcinai/phpi-websocket) for more on this.

External Devices
----------------

[](#external-devices)

There are included helper classes for interfacing with common devices, with more added regulary.

- Generic Inputs/Outputs
- Buttons
- LEDs
- Relays
- ADC (MCP 3xxx series)
- H Bridge Motors
- 2 and 4 Phase stepper motors

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~119 days

Total

15

Last Release

2978d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.5.0

v0.1.2PHP &gt;=5.4.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2415868?v=4)[Michael Calcinai](/maintainers/calcinai)[@calcinai](https://github.com/calcinai)

---

Top Contributors

[![calcinai](https://avatars.githubusercontent.com/u/2415868?v=4)](https://github.com/calcinai "calcinai (100 commits)")[![caveman99](https://avatars.githubusercontent.com/u/25002?v=4)](https://github.com/caveman99 "caveman99 (3 commits)")[![alcalyn](https://avatars.githubusercontent.com/u/1588144?v=4)](https://github.com/alcalyn "alcalyn (2 commits)")[![AlexQuinlivan](https://avatars.githubusercontent.com/u/3620511?v=4)](https://github.com/AlexQuinlivan "AlexQuinlivan (1 commits)")

---

Tags

websocketGPIOraspberrypispipwmrpi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/calcinai-phpi/health.svg)

```
[![Health](https://phpackages.com/badges/calcinai-phpi/health.svg)](https://phpackages.com/packages/calcinai-phpi)
```

###  Alternatives

[cboden/ratchet

PHP WebSocket library

6.4k22.3M252](/packages/cboden-ratchet)[gos/web-socket-bundle

Symfony Web Socket Bundle

6202.2M8](/packages/gos-web-socket-bundle)[piphp/gpio

A library for accessing the GPIO pins on a Raspberry Pi

4295.9k2](/packages/piphp-gpio)[rx/websocket

Websockets for PHP using Rx

34182.4k2](/packages/rx-websocket)[plesk/ratchetphp

PHP WebSocket library

1781.7k2](/packages/plesk-ratchetphp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
