38 min read

php-esp32-sdk 2.0: PHP firmware is now a Composer project

php-esp32-sdk 2.0.0 rebuilds PHP firmware for ESP32 as a Composer project: every hardware feature is a package, and phpbm drives a verified SDK download

Written by Gianfrancesco Aurecchia @GianfriAur
Release card: "Your firmware is a Composer project", with a composer.json that requires ext-gpio and sets sdk esp32@^2.0
FIG. 01 — Release card: "Your firmware is a Composer project", with a composer.json that requires ext-gpio and sets sdk esp32@^2.0

Today we are releasing php-esp32-sdk 2.0.0 Added in v2.0.0 · 2026-12 , and it is not an ordinary major version. It is a rewrite of how a PHP firmware is made. The idea underneath is unchanged: a microcontroller runs the real, unmodified PHP interpreter, the upstream Zend engine, cross-compiled for the chip. It is not a subset, a reimplementation or a transpiler. Your index.php is still the firmware. What changed is everything around that file: the project, the tool that builds it, where features come from, how boards are described, and the platform underneath.

In 1.x the firmware was one big repository that you configured with a TOML file and built. In 2.0 your firmware is a Composer project. Every hardware feature is a package you composer require. The SDK is a versioned download, and a command-line tool, phpbm, drives it. If you have written a Laravel app, most of a php-baremetal project will look familiar.

This article walks through every change between v1.5.0 and 2.0.0. It is long, because the release is big. If you only have two minutes, read the summary below and the quick start, then come back for the rest.

Tip TL;DR
  • A project is a composer.json. The SDK, board, runtime and storage sit under extra.baremetal, and the PHP version under config.platform.php.
  • phpbm 1.0.1 replaces phpflash. It runs on Linux, macOS and Windows and does the whole job: init, build, flash, sync, monitor, discover. It also manages SDKs and the toolchain.
  • Features are packages from https://repository.php-baremetal.com: 14 extensions, 10 device drivers, 13 PHP extensions. A firmware compiles only what it requires.
  • Boards are JSON files, many of them in board packages. They have real product names, can name their own pins (Pin::LED_BUILTIN), and a project can override their blocks. The Arduino Nano ESP32 and the Seeed Studio XIAO ESP32-S3 are new.
  • Slate (ext-slate 1.4.1) is a retained-mode 2D scene graph for display panels. It redraws only what changed.
  • ESP-IDF v6.1.1, PHP 8.6.0 next to 8.3.37, 8.4.28 and 8.5.13, a faster ESP32-S3, and four reliability fixes measured on hardware.

Side by side: in 1.5.0 one firmware repository held the extensions, drivers and boards, and the 1.x CLI built it from a TOML file; in 2.0.0 a Composer project requires packages from the registry, and phpbm builds it against a downloaded, verified SDK release

From one repository to a Composer project

A short definition first, since most readers come from PHP rather than embedded work. The firmware is the program a microcontroller runs from its own flash memory: there is no operating system underneath it to install apps on. You build it on your computer, which is cross-compilation, because the code is compiled for a different processor than the one doing the compiling. Then you flash it, which means writing the image to the board over USB. The set of compilers and tools that does the cross-compiling is the toolchain. On ESP32 chips that is Espressif's ESP-IDF framework, which also provides FreeRTOS, a small real-time operating system kernel (RTOS) that schedules tasks on the chip.

In 1.x all of this lived in one repository. The extensions for GPIO, I2C or Wi-Fi sat inside it as components/php_ext_*. The drivers for LEDs, sensors and displays sat there too. Boards were folders with internal names. A TOML file switched features on and off. To fix a bug in the I2C extension we had to release a whole new firmware, and your project was built against whatever version of those sources you had installed.

2.0 takes that repository apart and puts each piece where PHP developers expect it to be.

1.5.0 2.0.0
Project file TOML (php-esp32.config.toml) composer.json, with extra.baremetal
CLI phpflash, a single binary from the separate flash-tool repo phpbm, written in PHP, installed with Composer or as a PHAR
What the CLI builds against the sources installed by phpflash system-setup an SDK release downloaded and verified by phpbm
Extensions (GPIO, I2C, Wi-Fi…) built into the firmware repo, enabled in TOML separate Composer packages from the registry
Device drivers (LED, IMU, RTC, displays, touch) in the firmware repo separate packages, each registering into its bus extension
PHP's own extensions (mbstring, pdo, opcache…) build flags packages php-baremetal/php-<name>
Boards directories inside the firmware repo, internal names JSON board files in the SDK or in board packages, real product ids
PHP version build flag config.platform.php in composer.json
SDK version of a project whatever was installed the constraint "sdk": "esp32@^2.0", locked in phpbm.lock
Your own C code ./firmware/exts/ a native package, in C or C++

The left column is there for comparison only: those tools and files are retired, and nothing in 2.0 reads them.

Why this shape

A project carries only what it uses. In 1.x every firmware was built from the same tree and options trimmed it afterwards. In 2.0 the starting point is empty. A firmware without Wi-Fi does not compile Wi-Fi, and one without a display carries no display code. The image is exactly the sum of what composer.json requires.

Packages version on their own. A fix to the I2C extension ships as ext-i2c 1.2.1, and nobody waits for a new SDK. A new display driver is a new package. The SDK's own release cycle is reserved for the platform: the toolchain, the PHP builds, the runtimes.

Builds are reproducible. SDK releases are versioned archives listed in a release index with their sha256. phpbm verifies the hash of every SDK it downloads. The project locks the SDK version in phpbm.lock and its packages in composer.lock. Commit both files and a colleague, or a CI runner, builds the same firmware next month.

It looks like PHP. composer require php-baremetal/ext-gpio is how you add GPIO. Version constraints, composer update, composer outdated and private repositories all work the way they work in a web project, because it is the same Composer.

Anyone can publish a board or a driver. A vendor, a shop or a hobbyist can ship a board file or a sensor driver as a package on their own schedule, without forking the SDK and without waiting for us.

Quick start

This is the full path from an empty machine to a board running PHP. The commands are the same on Linux, macOS and Windows.

  1. Step 1: Install the tools

    phpbm is the command-line tool. conductor is the Composer plugin that installs bare-metal packages into a project. Both go in globally.

    bash
    composer global require php-baremetal/phpbm php-baremetal/conductor
    phpbm sdk:install esp32
  2. Step 2: Create the project

    phpbm init asks for the SDK, the board, the runtime and the storage. You can also pass them as flags.

    bash
    phpbm init blink && cd blink
  3. Step 3: Add the features

    Each feature is a package. Blinking an LED needs GPIO, plus ext-sys for delay().

    bash
    composer require php-baremetal/ext-gpio php-baremetal/ext-sys
  4. Step 4: Install the toolchain

    This is ESP-IDF v6.1.1, about 6 GB, installed once per machine in ~/.phpbm/toolchains/esp32.

    bash
    phpbm toolchain:install
  5. Step 5: Flash and watch

    flash builds the firmware if needed, checks the connected chip and writes the image. monitor opens the serial console.

    bash
    phpbm flash && phpbm monitor

The program is ordinary PHP. In the init-loop runtime, setup() runs once and loop() runs again and again:

php project-src/index.php
<?php
 
function setup(): void {
    gpio_mode(2, GPIO_OUTPUT);      // an LED on GPIO 2: use your board's LED pin
}
 
function loop(int $tick): void {
    gpio_write(2, $tick % 2);
    delay(500);
}

A GPIO (general-purpose input/output) is a pin of the chip that your code can drive high or low, or read. gpio_write(2, 1) puts 3.3 V on pin 2, and an LED wired to it lights up. Later in this article you will see how a board can name that pin for you, so the code can say Pin::LED_BUILTIN instead of a number.

Anatomy of composer.json

This is what phpbm init writes. Everything php-baremetal needs to know sits under extra.baremetal. The rest is plain Composer.

json composer.json
{
  "name": "local/blink",
  "type": "project",
  "repositories": [
    { "type": "composer", "url": "https://repository.php-baremetal.com", "canonical": true }
  ],
  "require": {
    "php-baremetal/conductor": "^1.0",
    "php-baremetal/boards-waveshare": "^1.0"
  },
  "config": {
    "allow-plugins": { "php-baremetal/conductor": true },
    "platform": { "php": "8.6.0" }
  },
  "extra": {
    "baremetal": {
      "sdk": "esp32@^2.0",
      "board": "waveshare-esp32-s3-touch-lcd-1.85b",
      "runtime": "init-loop",
      "storage": "embedded"
    }
  }
}

Three details are worth a closer look. The registry is declared canonical, so Composer takes php-baremetal packages from there and nowhere else. config.platform.php is no longer just a hint for dependency resolution: it is the PHP version compiled into the firmware. And the board comes from a board package, php-baremetal/boards-waveshare, which phpbm init added because the chosen board lives there. More on board packages later.

Keys of extra.baremetal
sdk
string required

The SDK and a version constraint, platform@constraint. esp32@^2.0 accepts any 2.x release. The version actually used is locked in phpbm.lock.

board
string required

The id of a board file, from the SDK or from an installed board package, for example espressif-esp32-s3-devkitc-1-n8r8. When two sources define the same id, pick one with <vendor>/<package>:<id> or sdk:<id>.

runtime
string required

How PHP runs on the chip: init-loop, event-driven or web-server.

storage
string required

Where the PHP code lives: embedded (in the flash image) or microsd (on the card, updated with phpbm sync).

src
string optional
default project-src

The folder with your PHP sources.

entry
string optional

The script the runtime starts.

env
string optional

A .env file whose values the firmware exposes as $_ENV and getenv(). Wi-Fi credentials belong here rather than in code.

options
object optional

SDK options (power-save, log, board-constants…) and package options (slate-effects, display-surface…).

board-overrides
object optional

Changes a block of the board, or adds one the board does not have.

assets
array optional

Files shipped with the firmware, embedded in flash or copied to the microsd card.

What happens on phpbm flash

The build is a chain of small, separately versioned pieces. Composer, through the conductor, resolves the packages. phpbm reads the manifest, fetches the SDK release named by the constraint and checks its sha256. The SDK prepares an ESP-IDF project with the board, the PHP build and the C code of each package. ESP-IDF compiles the image, and phpbm writes it to the chip.

The build chain: composer.json goes to Composer and the conductor, which install packages and bind each extension to its ESP32 HAL; phpbm reads the manifest, downloads the SDK release and checks its sha256 against phpbm.lock; the SDK prepares the ESP-IDF v6.1.1 project; ESP-IDF compiles the firmware; phpbm flashes the board

The interesting part sits between the extensions and the chip. An extension such as ext-gpio defines the PHP API: the functions, the classes, the checks on arguments. It does not touch the hardware. That job belongs to a HAL (hardware abstraction layer), a small package that implements the extension on one platform. The ESP32 HALs are named esp32-*-hal. An extension depends on a virtual HAL slot, and the conductor fills that slot with the HAL of the SDK the project uses. You never require a HAL yourself. That split is also what lets the same ext-gpio work on a future SDK for another chip family: a new chip means a new HAL, not a new extension.

phpbm 1.0: one tool for the whole workflow

phpbm replaces phpflash. It is written in PHP and runs on Linux, macOS and Windows. It needs PHP 8.4 or later, Composer 2 and git. You install it with Composer (composer global require php-baremetal/phpbm) or as a PHAR, with SHA256SUMS to check the download.

The design decision that shapes phpbm is that it knows nothing about any chip. It does not know what an ESP32 is, which flash layout it uses or how ESP-IDF is configured. Everything platform-specific comes from the SDK it downloads: the board files, the toolchain version, the build scripts, the chip checks. phpbm provides the workflow: projects, manifests, downloads, hashes, serial ports and file sync. So a new SDK for a new chip family will not need a new CLI.

The Composer plugin, php-baremetal/conductor, must be installed globally next to phpbm. It is the piece that installs the bm-* packages into the project and adds the ESP32 HAL that each extension needs.

phpbm 1.0.0 is the first stable release, and 1.0.1 followed the same day. The commands, grouped by when you use them:

phpbm 1.0 command map in four groups: project (init, board), build and run (build, flash, sync, monitor, discover), assets (font:bake, image:convert) and the machine (sdk:install, sdk:list, sdk:update, sdk:remove, sdk:link, toolchain:install, cache:clear, self-update)

Command What it does
init [dir] Creates a project. It asks for the SDK, board, runtime and storage, or takes the flags --sdk, --board, --runtime, --storage.
board [<board>] Adds or removes the board's features, or changes the board.
build [--clean] Builds the firmware.
flash [-p <port>] [--force] Builds if needed, checks the connected chip, flashes. For microSD projects it also copies the sources and assets to the card.
sync [-p <port>] Copies the sources and microSD assets to the board's card over the serial port, without rebuilding.
monitor [-p <port>] Opens the serial console.
discover [-p <port>] Lists the serial ports, the chip on each one and the boards that match it.
font:bake <source> --name=<name> Turns a TTF or BDF font into a font header for ext-display.
image:convert <input> <output> Turns a PNG into a .sli image for Slate.
sdk:install, sdk:list, sdk:update, sdk:remove, sdk:link Manage SDK versions. sdk:link points phpbm at a local checkout, for SDK development.
toolchain:install Installs the SDK's toolchain: ESP-IDF, about 6 GB, in ~/.phpbm/toolchains/esp32.
cache:clear Deletes downloaded archives and prepared sources.
self-update [--disable-check] [--enable-check] Updates phpbm.

A few commands worth knowing

phpbm discover answers the first question everyone has with a new board on the desk: what is plugged in? It lists every serial port, the chip connected to each one, and the board files that match that chip. You get a short list of board ids to pick from, not just a device path.

phpbm board is how a project follows the hardware. Run it with no argument and it offers the features the board has: a display, a touch screen, an LED. It adds or removes the matching packages. Run it with a board id and it moves the project to another board. Overrides that still make sense come along, and the ones that don't are listed and confirmed before they are dropped.

phpbm sync is what makes the microsd storage pleasant. The PHP code lives on the card, and sync copies the changed sources over the same USB cable you use for the console. There is no rebuild and no reflash, and the board runs the new code in seconds. It touches only the folders phpbm manages, never the rest of the card.

phpbm flash builds only when something changed, and checks the chip on the port before it writes, so a firmware for one chip does not end up on another.

An update check that asks first

Once a day, phpbm checks whether a newer stable release exists. When one does, it asks: yes, no or skip this version. Yes updates phpbm and runs the command you typed again, so nothing is lost. The check stays out of the way where it would be a nuisance. It is off in non-interactive runs and in CI, and you can turn it off with the PHPBM_NO_UPDATE_CHECK environment variable, the --no-update-check flag or phpbm self-update --disable-check.

phpbm 1.0.1 fixes the one rough edge of 1.0.0. The "manifest older than composer.json" check now compares Composer's content-hash instead of file times, so it no longer fires right after phpbm init.

Your IDE understands the firmware

The firmware's classes and functions, gpio_write(), Baremetal\I2c\Bus, the Slate elements, live in C, not in PHP files. Without help an IDE marks them all as undefined. In 2.0 every package with a PHP API ships IDE stubs: declarations with empty bodies, exact signatures and documentation. The conductor collects them into vendor/ on every install, so PhpStorm, or VS Code with Intelephense, autocompletes them with nothing to configure.

The board gets the same treatment. phpbm writes .phpbm/ide/board.php with the board's pin constants, and rewrites it at init, at board and at every build. Type Pin:: and the editor offers D13, A3 and LED_BUILTIN for the board you picked. Keep .phpbm/ide/ in the index, even if you exclude the build folders.

Every feature is a package

Every package below comes from the registry at https://repository.php-baremetal.com and installs with composer require php-baremetal/<name>. The versions are the ones at launch. They will move on their own from now on, which is the point.

Extensions: the PHP API

An extension is the part PHP sees: functions, classes, constants, events. Here is the launch set:

Package Version What it gives PHP
ext-events 1.2.1 The event bus: events, listeners, a timer, pin and button sources. Every firmware requires it.
ext-gpio 1.2.0 Digital I/O, the gpio_* functions.
ext-sys 1.1.1 Delay, uptime, restart, deep sleep and wake cause, reset reason, chip info, memory.
ext-i2c 1.2.1 Baremetal\I2c\Bus and Device, and the framework I2C drivers plug into.
ext-spi 1.1.1 Baremetal\Spi\Bus and Device, and the SPI driver framework.
ext-led 1.1.2 Baremetal\Led\Device and the addressable-LED driver framework.
ext-wifi 1.2.0 Wi-Fi scan, connect and access point, from PHP.
ext-web 1.1.0 Baremetal\Http\Request and Response, serve_http() and serve_ws(): HTTP and WebSocket as event sources.
ext-store 1.1.1 A persistent key-value store that survives resets and power cuts.
ext-mem 1.1.0 An in-RAM key-value store shared across requests.
ext-display 1.2.1 A display surface: framebuffer, drawing primitives, bitmap fonts, region flush.
ext-input 1.1.0 Touch input: the Touch interface, Pressed, Moved, Released and Gesture events, multi-touch.
ext-slate 1.4.1 Slate, a retained-mode 2D scene graph and compositor (below).
ext-hello 1.1.0 A demo extension.

I2C and SPI are the two serial buses that connect a microcontroller to the chips around it. I2C uses two wires and an address for each chip; it carries sensors, clocks and touch controllers. SPI uses more wires and runs faster; it carries displays and memory cards.

Device drivers

A driver is the code for one specific chip on a bus: this accelerometer, that touch controller. In 2.0 each driver is its own package and registers itself into its bus extension. That is why $bus->scan() can tell you which driver claims each address it finds.

Package Version Device
led-ws2812 1.1.0 WS2812 RGB LEDs
led-sk6812 1.1.0 SK6812 RGBW LEDs
imu-qmi8658 1.1.1 QMI8658 6-axis IMU
mag-mmc5603 1.1.0 MMC5603NJ magnetometer
rtc-pcf85063 1.1.0 PCF85063 real-time clock
touch-cst816s 1.1.0 CST816S touch controller
touch-gt911 1.0.0 GT911 touch controller, up to five fingers
io-ch422g 1.0.0 CH422G I/O expander
esp32-display-st77916 1.2.0 ST77916 QSPI round display
font-dejavu 1.0.0 DejaVu Sans bitmap fonts at 12, 16 and 24 px, anti-aliased

Drivers are classes in 2.0. Lighting a strip of eight WS2812 LEDs takes one composer require and a few lines of PHP:

php project-src/index.php
<?php
use Baremetal\Led\Driver\Ws2812;
 
$strip = new Ws2812(pin: 5, count: 8);       // GRB order, all pixels off
 
for ($i = 0; $i < $strip->count(); $i++) {
    $strip->hsv($i, $i * 45, 255, 32);       // a dim rainbow into the buffer
}
$strip->show();

Package layers: your PHP calls an extension (ext-gpio, ext-i2c, ext-led); each extension depends on a virtual HAL slot that the conductor binds to the esp32 HAL; drivers such as led-ws2812 or imu-qmi8658 register into their bus extension; the HALs sit on ESP-IDF and the chip

The same split explains onboard(). A driver can read the board file (next section), so Ws2812::onboard() already knows the pin and colour order of the LED soldered on your board, and Slate::onboard() knows the board's panel and touch screen. You write the pin number only when you wired something yourself.

PHP's own extensions

PHP's bundled extensions are packages too, named php-baremetal/php-<name>. Thirteen of them are available: bcmath, ctype, date, filter, mbstring, opcache, openssl (partial API), pdo, pdo_sqlite, session, sqlite3, tokenizer and zlib. You enable one by requiring it, and leave it out to save its flash. Want SQLite on a microSD card? Require php-baremetal/php-pdo and php-baremetal/php-pdo_sqlite, then use PDO as you always have.

The infrastructure you never touch

Three more kinds of package exist. You will rarely name them, but they show up in composer.lock. The HAL packages (esp32-*-hal) implement each extension on ESP-IDF, and the conductor picks the right one. bm-common holds the C headers shared by the packages. spec (php-baremetal/spec 1.5.0) is the shared model of the build manifest: phpbm and the SDK both use it, so they always agree on what a project means.

Writing your own

The package format is open, and 2.0 makes writing a native package simpler:

  • C or C++. A package that does not list sources compiles every src/*.c and src/*.cpp it has. phpbm.h has C linkage when included from C++, so an existing C++ library for a sensor can be wrapped without a C shim. The module entry and the registered symbols need C linkage, as the SDK's firmware rules explain.
  • Package options. A package declares options in extra.baremetal.options, and the build defines PHPBM_OPTION_<NAME> for each one, so your C code can #if on it. An option of type set takes a list of allowed values. The build defines PHPBM_OPTION_<NAME>_<VALUE> as 1 or 0 for each allowed value, plus PHPBM_OPTION_<NAME> as the comma-separated values chosen. ext-slate uses this to compile only the graphic effects a project asks for.
  • Fonts and board blocks. A package can declare fonts (extra.baremetal.fonts) that the build compiles into the firmware. It can also declare the board blocks it uses (extra.baremetal.board-blocks), so that phpbm board offers it when a board has that feature. Before 2.0, a custom extension meant copying C files into ./firmware/exts/ of one project. Now it is a package, with a version, that you can share between projects or publish.

Highlight

The package we are most excited about in this release.

Slate: a scene graph for small screens

Drawing on a microcontroller display usually means pushing pixels: clear a region, draw a rectangle, draw the text again, send the framebuffer, for every frame. That is a lot of code to get right, and a lot of time spent drawing pixels that did not change.

ext-slate takes the opposite approach. It is a retained-mode 2D scene graph: you describe what is on the screen, and Slate remembers it. A script builds scenes out of elements, RoundRect, Circle, Arc, Line, Text, Canvas and Group, and from then on it only changes their properties. Slate works out what changed and composes only that part of the screen. It works band by band, at the pace of the panel. A screen that does not change costs no frame at all.

php project-src/index.php
<?php
use Baremetal\Slate\{Slate, Scene, RoundRect, Text, Align};
 
final class Home extends Scene
{
    protected function build(): void
    {
        $this->add(
            new RoundRect(0, 0, 360, 360, fill: 0x0B1020),
            new Text(180, 170, 'Hello', align: Align::Center),
        );
    }
}
 
$slate = Slate::onboard();       // the board's own panel and touch screen
$slate->show(new Home());

A page is a class that extends Scene. Its components are built in build(), and onEnter(), onLeave() and onTouch() are called when the page is shown, replaced and touched. A reusable component of your own, a gauge or a button, extends Group.

How Slate composes a frame: the scene graph marks the elements whose properties changed, their dirty rectangles are merged, the screen is cut into bands, and only the bands under the change are composed; the other bands cost nothing, and a still screen costs no frame

Beyond flat shapes, Slate draws gradients, shadows and blur. It handles touch, and it has a built-in profiler you switch on with one option ("slate-debug": true): frames per second on screen and a line of timings per second on the console. Effects you do not use can be left out of the build with slate-effects, and their code is never compiled. Images come from ordinary PNG files: declare them as project assets and phpbm converts them to Slate's .sli format with phpbm image:convert.

Slate runs best in the event-driven runtime. The listeners change the elements, and all the changes of one listener appear together in the same frame. The examples 06-display/slate-hello, 06-display/slate-gauge, 06-display/slate-stress and 06-display/slate-bench run on the Waveshare ESP32-S3-Touch-LCD-1.85B, a 360 x 360 round panel. On that board the profiler reads 0.0 fps on a still screen, and the slate-gauge example, driven by the tilt of the on-board IMU, runs at 60 frames per second.

Boards are data: JSON files, board packages and pin names

In 1.x a board was a folder inside the firmware repository, with an internal short name that matched no product. In 2.0 a board is a JSON file with a real product id. It describes the chip, the PSRAM, the flash, the console and the network, and lists the peripherals soldered on the board as blocks: display, i2c, touch, expander, led, microsd and so on.

PSRAM is extra RAM on a separate chip next to the processor. A microcontroller's own RAM is measured in hundreds of kilobytes, which is not enough for the Zend engine and a real application. php-baremetal boards carry from 2 MB up to 32 MB of PSRAM, and that is where PHP's memory lives.

Packages read the board's blocks. So a driver knows the pins of the on-board display, the address of the IMU and the data pin of the RGB LED without one line of configuration in your project. Here is the file of the Espressif ESP32-S3-DevKitC-1 (N8R8), exactly as it ships in the SDK:

json boards/espressif-esp32-s3-devkitc-1-n8r8.json
{
    "name": "Espressif ESP32-S3-DevKitC-1 (N8R8)",
    "chip": "esp32s3",
    "psram": "octal",
    "flash": "8MB",
    "network": {
        "type": "wifi"
    },
    "led": {
        "type": "ws2812",
        "pin": 48,
        "order": "grb"
    }
}

Anatomy of a board file: top-level keys describe the chip, PSRAM, flash and console; blocks describe on-board peripherals; the SDK implements the microsd and network blocks itself, while packages read display, i2c, touch, led and expander blocks through onboard()

Overrides: change a block, or add one

Real hardware drifts from the board file. You wired a microSD slot to a generic module, or your Ethernet chip sits on other pins. board-overrides in extra.baremetal handles both cases without editing the board file. An entry for a block the board has is merged over it: the keys you give replace the board's values, and the rest stay. An entry for a block the board does not have adds it, and then you write it whole, with its type.

This project puts an SPI microSD slot on a generic ESP32-S3 board, and keeps a folder of photos on the card:

json composer.json
{
  "extra": {
    "baremetal": {
      "sdk": "esp32@^2.0",
      "board": "generic-esp32s3-octal",
      "runtime": "init-loop",
      "storage": "embedded",
      "assets": [
        { "dir": "assets/photos", "storage": "microsd" }
      ],
      "board-overrides": {
        "microsd": { "type": "spi", "cs": 10, "sclk": 12, "mosi": 11, "miso": 13 }
      }
    }
  }
}

The build checks every pin before it writes anything. The type must be one the chip supports (spi for microSD on the ESP32-S3, sdio on the ESP32-P4). Every pin the type needs must be there, and each pin must be a GPIO number of the chip: 0 to 48 on the ESP32-S3, 0 to 54 on the ESP32-P4. A forgotten pin is a clear message that names it, such as microsd.cs is missing (a 'spi' microsd needs cs, sclk, mosi, miso). It is not a C compile error three hundred lines into an ESP-IDF log.

Do

Describe your own wiring in board-overrides, in the project. It survives SDK updates, and phpbm board carries it to another board when it still fits.

Don't

Copy and edit a board file from the SDK for a two-pin change. Your copy stops getting fixes, and a type change (turning a W5500 network into Wi-Fi) is not something overrides allow anyway: pick another board.

Board packages

Vendors' boards now live in their own packages, of Composer type bm-boards. When you pick one of their boards, phpbm init adds the package. The SDK keeps the Espressif and generic boards. Anyone can publish a board package, so a new board does not have to wait for an SDK release. Each source also has a boards/catalog.json with the documentation page and product photo of each board. phpbm and the registry's board pages use it.

These are the boards at launch:

Boards at launch, by source: the SDK itself (Espressif ESP32-S3-DevKitC-1 N8R2, N8R8, N16R8; generic ESP32-S3 quad and octal PSRAM; generic ESP32-P4), boards-waveshare 1.0.0 (eight boards, two of them new), boards-freenove 1.0.0, boards-arduino 1.0.0 (new) and boards-seeed 1.0.0 (new) In the SDK

  • Espressif ESP32-S3-DevKitC-1 (N8R2, N8R8, N16R8)
  • Generic ESP32-S3 (quad PSRAM, octal PSRAM) and generic ESP32-P4 php-baremetal/boards-waveshare 1.0.0
  • Waveshare ESP32-S3-Zero (and its N8R8 variant), ESP32-S3-ETH, ESP32-S3-Touch-LCD-1.85B
  • Waveshare ESP32-S3-Touch-LCD-5B (new)
  • Waveshare ESP32-P4-ETH, ESP32-P4-Pico, ESP32-P4-WIFI6
  • Waveshare ESP32-P4-WIFI6-Touch-LCD-5 (new) php-baremetal/boards-freenove 1.0.0
  • Freenove ESP32-S3 WROOM Board Lite (N16R8, N16R16) php-baremetal/boards-arduino 1.0.0 (new)
  • Arduino Nano ESP32, with its pin names: D0 to D13, A0 to A7, LED_BUILTIN and the rest php-baremetal/boards-seeed 1.0.0 (new)
  • Seeed Studio XIAO ESP32-S3, with its pin names: D0 to D10, A0 and up, LED_BUILTIN and the rest Every name above is the product's real name. The short internal names of 1.x are gone. A board's id stays stable, and phpbm discover tells you which ids match the chip on your desk.

Pin names in PHP

The Arduino and Seeed boards bring a feature that every board can use: pin names. A board file can name its GPIOs in a top-level pins object, and the firmware exposes the names to PHP.

json boards/esp32/arduino-nano-esp32.json of php-baremetal/boards-arduino (excerpt)
{
    "pins": {
        "D13": 48,
        "A3": 4,
        "A4": 11,
        "A5": 12,
        "LED_BUILTIN": 48
    },
    "i2c": { "type": "i2c", "sda": "A4", "scl": "A5" }
}
php project-src/index.php
<?php
use Baremetal\Board\Pin;
 
function setup(): void {
    gpio_mode(Pin::LED_BUILTIN, GPIO_OUTPUT);   // GPIO 48 on the Arduino Nano ESP32
}
 
function loop(int $tick): void {
    gpio_write(Pin::LED_BUILTIN, $tick % 2);
    delay(500);
}

Pin names from the silkscreen to PHP: the Arduino Nano ESP32 labels D13, A3 and LED_BUILTIN; its board file maps them to GPIO 48, 4 and 48; the firmware registers them as constants of Baremetal\Board\Pin, so Pin::A3 === 4

The rules are short:

  • final class Baremetal\Board\Pin always exists. It is registered once at startup, with one int constant per name, and it is empty when the board names no pins. use Baremetal\Board\Pin works on every board, and a name the board does not define is an ordinary undefined-constant error.
  • Arduino-style globals are one option away. With the SDK option board-constants set to global (the default is class), the names are also global constants: A3, D13. A name that clashes with a PHP constant is then a build error, not a surprise at runtime.
  • Blocks can use the names. "sda": "A4" in a board block means GPIO 11, and the same works inside board-overrides.
  • The IDE knows them. phpbm writes .phpbm/ide/board.php, so Pin:: autocompletes for the board you picked. Pin names make examples portable. A sketch that blinks Pin::LED_BUILTIN runs on the Arduino Nano ESP32 and the Seeed Studio XIAO ESP32-S3 without editing a number.

Two large-display boards

Two new Waveshare boards in boards-waveshare stretch what php-baremetal targets. Their screens are a lot bigger than a 360 x 360 round panel.

Two new large-display boards: the Waveshare ESP32-S3-Touch-LCD-5B with a 1024 x 600 RGB panel at 26 MHz, two framebuffers, GT911 touch and a CH422G expander; the Waveshare ESP32-P4-WIFI6-Touch-LCD-5 with a 720 x 1280 MIPI-DSI panel turned to 1280 x 720, two framebuffers, GT911 touch polled every 10 ms, Wi-Fi through an ESP32-C6 and microSD

  • Waveshare ESP32-S3-Touch-LCD-5B: a 1024 x 600 parallel RGB panel at a 26 MHz pixel clock, with two framebuffers, GT911 touch and a CH422G I/O expander. The expander's pins can be named in other blocks, so the backlight is simply exio2.
  • Waveshare ESP32-P4-WIFI6-Touch-LCD-5: a 720 x 1280 MIPI-DSI panel turned to 1280 x 720, with two framebuffers, GT911 touch, Wi-Fi through the on-board ESP32-C6 and a microSD slot. The GT911's interrupt line is not wired on this board, so the touch driver reads the chip every 10 ms instead. The board files, the rgb and dsi display blocks and the build support for both panels are in 2.0.0. The panel drivers themselves, esp32-display-rgb and esp32-display-dsi, are separate packages and are not released yet: the panels need them.

Under the hood: platform, performance and reliability

ESP-IDF v6.1.1 and PHP 8.6

The firmware now builds on ESP-IDF v6.1.1, up from v5.5.5. That is a new major version of Espressif's framework, and it brings fixes for the memory protection set-up of the ESP32-P4 v3. phpbm toolchain:install installs it, and you never configure ESP-IDF by hand.

PHP 8.6.0 joins the supported versions, and phpbm init now picks it by default. It carries the same patches as 8.5, ported, and the same thirteen optional extensions. date gains Time\Duration, and the new Io\Poll API runs on ESP-IDF's poll(). Because 8.6's engine relies on OPcache internally, the SDK always links OPcache with 8.6, as PHP itself does. Without php-baremetal/php-opcache it stays disabled, with no cache and no PSRAM reserved. As on 8.5, the WHATWG URL parser is not built.

The other versions move to their latest patch releases: PHP 8.3.37, 8.4.28 and 8.5.13. Choosing a version is one line, config.platform.php in composer.json.

Runtimes, storage and networks

The three runtimes and two storages of 1.x carry over unchanged in behaviour. You now pick them in composer.json instead of a TOML file. A runtime is the way PHP is driven on the chip:

setup() once, then loop() again and again, like an Arduino sketch. It is the simplest model, and the loop-interval option belongs to it.

php project-src/index.php
<?php
function setup(): void {
    gpio_mode(2, GPIO_OUTPUT);
}
 
function loop(int $tick): void {
    gpio_write(2, $tick % 2);
    delay(500);
}

Storage decides where your PHP code lives. With embedded it is baked into the flash image next to the firmware: robust, and nothing to lose. With microsd it sits on the memory card, and phpbm sync updates it over the serial port without a reflash, which is the fastest edit-run loop available. It also makes room for projects far larger than the flash, such as a full framework.

Networks come in three kinds: the chip's own Wi-Fi, Ethernet through the ESP32-P4's built-in MAC (EMAC) or a W5500 chip, and Wi-Fi through an ESP32-C6 companion chip on boards like the ESP32-P4-WIFI6. The board file says which one a board has.

The SDK options, set in extra.baremetal.options: network, on-error, restart-delay, firmware-reserve, optimization, log, power-save (automatic light sleep), request-timeout and the new board-constants, plus loop-interval for init-loop and init and port for web-server.

Project assets

Added in v2.0.0 · 2026-12 A firmware often needs files that are not PHP: images for Slate, a web page to serve, a lookup table. `extra.baremetal.assets` declares folders of them, and each folder goes either `embedded` into the flash image or to the `microsd` card. With microSD assets the firmware mounts the card even when the code is in flash. `phpbm flash` and `phpbm sync` copy them across, and only the folders phpbm manages are touched. Your logs, databases and anything else on the card stay where they are.

Displays: fonts and framebuffers

  • Fonts are compiled in. The fonts a project uses, from font-dejavu or another package, are resolved by phpbm and compiled into the firmware for ext-display. phpbm font:bake turns any TTF or BDF font into a new one.
  • Framebuffers take care of themselves. A framebuffer is the block of memory that holds one full screen of pixels. A 1024 x 600 panel at two bytes per pixel needs about 1.2 MB for each one. The build now reserves the framebuffers of the board's display outside PHP's memory automatically, so a large panel needs no option.
  • More room for Slate. The firmware-reserve option, the PSRAM kept outside PHP for images and Slate's caches, can now go up to 8192 KB (it was capped at 4096), still at most a quarter of the free PSRAM. On the 32 MB Waveshare ESP32-P4-WIFI6-Touch-LCD-5 that is about 7.7 MB for Slate's caches and images.
  • MIPI-DSI and RGB blocks. The build knows both kinds of large panel. A turned DSI panel normally needs an extra drawing surface. With ext-display's display-surface option set to false it can be left out, which saves 1800 KB on the Waveshare ESP32-P4-WIFI6-Touch-LCD-5.

A faster ESP32-S3

The ESP32-S3 gets a set of tuning changes. Together they make PHP noticeably quicker and leave room for Wi-Fi next to a large display:

ESP32-S3 tuning in 2.0.0 against ESP-IDF defaults and 1.5.0: CPU clock 160 to 240 MHz, instruction cache 16 to 32 KB, main task stack 32 to 8 KB (24 KB of internal RAM back), and the firmware-reserve option's cap 4096 to 8192 KB

  • CPU at 240 MHz. The ESP-IDF default is 160 MHz.
  • A 32 KB instruction cache, where the default is 16 KB. PHP and the drawing code run from flash, through this cache, so doubling it means fewer slow trips to flash.
  • Main task stack down to 8 KB from 32 KB. PHP runs in its own task, and the main task only boots, mounts the storage, restarts and sleeps. Measured on the board, it uses about 1 KB of its stack. The 24 KB go back to internal RAM, which Wi-Fi needs when it shares the chip with a large display.
  • Wi-Fi buffers in PSRAM. A board can move the Wi-Fi buffers to PSRAM (network.buffers: "psram") and tune how many it keeps (network.static-buffers). This is what lets Wi-Fi start next to the 1024 x 600 RGB panel and Slate on the Waveshare ESP32-S3-Touch-LCD-5B.
  • QIO flash (flash-mode: qio) on ESP32-S3 and ESP32-P4 boards that support it. The flash is read over four data lines.

Rock solid

Four fixes, each measured on hardware before and after.

Reliability

Reliability fixes, before and after on hardware: cold starts crashing with zend_mm_heap corrupted from up to 20 of 20 to 0 of 20; ESP32-P4 boot faults from all 102 starts to none; closure memory growth from about 49 bytes per bind to constant over 9 000 000 rounds; out of memory from a reboot to a fatal error with file and line

Running out of memory is an error, not a reboot. When a script exceeds PHP's memory limit, you now get a clean fatal error with the file and line, as on a server. Before, the board rebooted and left you guessing.

No more random zend_mm_heap corrupted at start. PHP's memory manager assumes every new chunk of memory starts zeroed, as it does on a server, where the operating system hands out clean pages. On the board, PHP's pool lives in PSRAM, which holds random bytes after power-on, so a stale bookkeeping page could hand out memory that was already in use. Large apps crashed while their scripts compiled at start. PHP's memory chunks now start with a zeroed header. On the Waveshare ESP32-P4-WIFI6-Touch-LCD-5 one app had crashed in up to 20 of 20 cold starts. With the fix it crashed in 0 of 20.

The ESP32-P4 boot fault is gone. At start, ESP-IDF's second core polled the scheduler with no pause. On the ESP32-P4, whose two cores share a data cache, this could stall the first core before app_main, depending on how the firmware was laid out. One affected image faulted on all 102 starts before the fix and on none after. The fix adds at most 10 µs to boot.

A closure memory leak is removed. A PHP patch from 1.x leaked about 49 bytes on every bind or bindTo in apps whose request never ends, such as event-driven ones. In a closure stress test it reached the memory limit after about 470 000 rounds. Without the patch, 9 000 000 rounds, ten minutes of closure stress, ran with memory_get_usage() constant.

Frameworks still run

Stock Laravel, Symfony 7.4 and Eloquent still run on ESP32-P4 boards with a microSD card. The framework keeps its own, unmodified Composer project inside project-src. The examples are in 09-frameworks/: 09-frameworks/eloquent, 09-frameworks/laravel-demo, 09-frameworks/laravel-demo-optimized and 09-frameworks/symfony-demo. That a full framework boots on a microcontroller is still the clearest proof that this is the real PHP interpreter, not an imitation of it.

Documentation

The SDK repository has new documentation in docs/, starting at docs/overview.md. It covers getting started, boards and board files, the runtimes, every module, the options, memory and flash, power saving, troubleshooting, and how to work on the SDK itself. phpbm has its own documentation in its repository.

Get started with 2.0.0

What ships today

php-esp32-sdk 2.0.0 release datasheet: php-esp32-sdk 2.0.0, phpbm 1.0.1, php-baremetal/spec 1.5.0, conductor 1.1.0, ESP-IDF v6.1.1, PHP 8.3.37, 8.4.28, 8.5.13 and 8.6.0

Piece Version
php-esp32-sdk 2.0.0
phpbm 1.0.1 (1.0.0, the first stable release, came out the same day)
php-baremetal/spec, the shared build model 1.5.0
php-baremetal/conductor, the Composer plugin 1.1.0
ESP-IDF v6.1.1 (1.5.0 used v5.5.5)
PHP 8.3.37, 8.4.28, 8.5.13 and 8.6.0 (new)

No board? Run it in the browser

If there is no board on your desk yet, the simulator at https://sim.php-baremetal.com runs PHP on an emulated ESP32-S3 in your browser. You edit index.php and composer.json in the page and press Run. The server builds the firmware with phpbm, using packages from the same registry, and the emulated chip boots it. There is nothing to install and nothing to flash. It comes with ready examples, Blink SOS, Button to LED, an I2C clock (DS3231) and Button events in the event-driven runtime, and it targets PHP 8.5.

The simulator is built on Velxio by David Montero Crespo, an independent open-source emulator (AGPLv3), and its own source is in the php-baremetal/php-baremetal-sim repository. It is the quickest way to feel how a php-baremetal project works. Timing in an emulator is not the timing of real silicon, so measure on a board.

Where to go next

  1. Step 1: Install

    composer global require php-baremetal/phpbm php-baremetal/conductor, then phpbm sdk:install esp32.

  2. Step 2: Read

    The SDK documentation starts at docs/overview.md in https://github.com/php-baremetal/php-esp32-sdk (release v2.0.0). The tool is documented at https://www.php-baremetal.com/documentation/phpbm and in https://github.com/php-baremetal/phpbm.

  3. Step 3: Browse

    Every extension, driver and board package is at https://repository.php-baremetal.com, with its own documentation page.

  4. Step 4: Build

    phpbm init, pick your board, composer require what you need, phpbm flash.

The ESP32 is the target today, not the identity of the project. 2.0 was designed so that a new chip family is a new SDK and a new set of HALs, while the engine, phpbm, the extensions and your PHP stay the same. If you build something with 2.0, a board package, a driver or a project, we would like to see it.

Note Trademarks

php-baremetal is an independent open-source project (MIT licence). It runs the unmodified upstream PHP interpreter and is not affiliated with or endorsed by the PHP Group. ESP32 and ESP-IDF are trademarks of Espressif Systems. Arduino, Seeed Studio, Waveshare and Freenove are trademarks of their respective owners. Their boards are named here for compatibility only, and no endorsement is implied. Laravel, Symfony and Composer are trademarks of their respective owners. The simulator is built on Velxio, an independent project.

Keep reading

More field notes.

All articles →