Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/ext-store

bm-ext MIT

Persistent key-value store: survives resets and power cuts.

A persistent key-value store for the PHP that runs on your board. store_set() writes a string to flash and store_get() reads it back after a reset or a power cut. Keys are 1 to 15 bytes, values are strings, and every write is committed before the call returns.

ext-store is platform-neutral: it requires the virtual php-baremetal/store-hal, and conductor adds the HAL for your SDK platform (php-baremetal/esp32-store-hal on ESP32, which keeps the data in NVS flash in its own phpstore partition of 24K). Nothing to configure: the partition comes with the HAL.

Install

In a project created with phpbm init:

bash
composer require php-baremetal/ext-store

Example

php
<?php
if (store_available()) {
    $boots = (int) store_get('boots', '0') + 1;   // values are strings
    store_set('boots', (string) $boots);
    echo "boot #$boots\n";
}

Documentation

Values that change often and need not survive a reset belong in ext-mem.

License

MIT.

Read the full documentation