init-loopSketch
- REQUIRES
- nothing
- POWER-SAVE
- light sleep between loop() calls
setup() once, then loop($tick) forever. Firmware-style control of pins and peripherals.
The upstream Zend engine from php.net, cross-compiled for the chip and booting straight into your
index.php.
Not a subset. Not a reimplementation. Not a transpiler.
PREVIEW phpbm and the 2.0 SDK are previews, not ready for production. Need something stable today? Stay on the 1.x firmware (tag v1.5.0).
Nothing between your code and the chip has been rewritten. The official engine runs through the official embed SAPI, with the standard library and real extensions compiled in.
composer require php-baremetal/ext-gpio.The official interpreter from the php.net release, cross-compiled for the chip with a few build-time patches. Nothing re-implemented.
Fig. 2 — Hover or tap a layer. Orange = php.net source.
A Composer project and an Arduino-style sketch: setup() runs once,
loop() runs forever. Press run, drag the delay: the code, the LED, the
trace and the pin on Fig. 1 follow along.
1 { 2 "name": "local/blink", 3 "type": "project", 4 "repositories": [ 5 { "type": "composer", "url": "https://repository.php-baremetal.com", "canonical": true } 6 ], 7 "require": { 8 "php-baremetal/conductor": "^1.0", 9 "php-baremetal/ext-gpio": "^1.0",10 "php-baremetal/ext-sys": "^1.0"11 },12 "config": {13 "allow-plugins": { "php-baremetal/conductor": true },14 "platform": { "php": "8.5.11" }15 },16 "extra": {17 "baremetal": {18 "sdk": "esp32@^2.0",19 "board": "waveshare-esp32-s3-zero-n8r8",20 "runtime": "init-loop",21 "storage": "embedded"22 }23 }24 }
L9–10 the features: ext-gpio gives gpio_*(), ext-sys gives delay(). The conductor adds the HAL for the SDK's platform.
L17–22 what to build it for: the SDK, the board, the runtime and where the code lives.
1 <?php 2 3 function setup(): void { 4 gpio_mode(2, GPIO_OUTPUT); 5 } 6 7 function loop(int $tick): void { 8 gpio_write(2, $tick % 2); delay(500); 9 echo "tick $tick: LED " . ($tick % 2 ? "ON" : "OFF") . "\n";10 }
L8–9 run on every tick: the highlight follows the board on the right.
ESP-ROM:esp32s3-20210327Build:Mar 27 2021rst:0x15 (USB_UART_CHIP_RESET),boot:0x2b (SPI_FAST_FLASH_BOOT)entry 0x403c8900I (512) esp_psram: Found 8MB PSRAM deviceI (751) cpu_start: cpu freq: 160000000 HzI (752) app_init: ESP-IDF: v6.1I (758) main_task: Calling app_main()phpbm: storage embeddedblink 0.1.0: PHP 8.5.11 on Waveshare ESP32-S3-Zero (N8R8) (esp32s3), ESP-IDF v6.1, core 1--- /app/index.php (init-loop) ---
$ phpbm monitor · sample output
$ phpbm init blink && cd blink
$ composer require php-baremetal/ext-gpio php-baremetal/ext-sys
$ phpbm toolchain:install
$ phpbm flash && phpbm monitor
sim.php-baremetal.com emulates an ESP32-S3 in QEMU, right in the browser.
It runs real firmware, built by phpbm with the esp32 SDK: the same engine your board would boot.
Open an example like the blink, edit index.php and
composer.json, and try it before you own any hardware.
Pick a runtime in composer.json → extra.baremetal
and the SDK wraps it around your code. PHP runs on core 1; the firmware's own tasks run on core 0.
init-loopsetup() once, then loop($tick) forever. Firmware-style control of pins and peripherals.
web-serverAn HTTP server that runs index.php per request: the PHP you already know, from a chip on your desk.
event-drivenA resident reactor: firmware tasks on core 0 catch timer, GPIO, HTTP and WebSocket events and hand them to your PHP listeners on core 1.
The diagrams are schematic, not measurements. Light sleep needs the SDK's power-save option.
Real extensions, not stubs. Networking, storage and state built for a device that never reboots on purpose.
ext-wifi scans, joins a network or opens an access point. On the ESP32-P4-WIFI6 through its ESP32-C6 companion.
Serve pages with the web-server runtime, or keep state with ext-web and push to every client with ws_broadcast().
pdo_sqlite and sqlite3 compiled into the engine. Eloquent runs on an ESP32-P4 with its database on the card.
store_* keeps keys in flash across resets; mem_* shares values in RAM between the requests of one boot.
Ship code on a card for quick swaps (phpbm sync), or embed it in flash.
Pins, inputs and outputs as plain PHP function calls: gpio_mode(), gpio_write(), gpio_read().
Timers, pin and button watchers; ext-i2c samples sensors in the background and hands readings to PHP as events.
Hardware extensions like ext-gpio and ext-sys install with composer require. The conductor adds the HAL for your chip.
bcmath
ctype
date
filter
mbstring
opcache (no JIT)
openssl (ciphers)
pdo
pdo_sqlite
session
sqlite3
tokenizer
zlib
ext-gpio
ext-sys
ext-wifi
ext-web
ext-events
ext-i2c
ext-spi
ext-led
ext-store
ext-mem
phpbm knows nothing about chips. Each SDK brings its boards, PHP build recipe, runtimes and toolchain; phpbm downloads, verifies and drives it. ESP32 is the first. STM32, NXP and RP2350 are planned: same project, same commands.
You're too curious come back at the end of November
init
build
flash
sync
monitor
discover
sdk:install
toolchain:install
repository.php-baremetal.com is the official Composer registry for the bm-* packages.
phpbm init wires it into your composer.json; then it's just
composer require.
composer global require php-baremetal/phpbm php-baremetal/conductor
phpbm sdk:install esp32
phpbm init blink
composer require php-baremetal/ext-gpio php-baremetal/ext-sys
phpbm toolchain:install
phpbm flash