Offline-write support is beta in the libSQL PHP extension (1.7.0+) and comes in two flavors. They are not interchangeable: each writes to a different system and needs different setup.
Flavor 1 — Turso Cloud (remote_replica mode)
DB_CONNECTION=libsql
DB_DATABASE=database.sqlite
DB_AUTH_TOKEN=<cloud-token>
DB_SYNC_URL=libsql://<db-name>-<org>.turso.io
DB_OFFLINE_WRITES=true
# Leave DB_SQLD_OFFLINE_MODE=false or omit it
Activation: offlineWrites => true without sqldOfflineMode.
Behavior: writes are journaled locally against the embedded replica.
DB::sync() pushes the journal to Turso Cloud.
use Illuminate\Support\Facades\DB;
DB::sync();
Fresh-replica ordering matters
On a fresh local replica file, call DB::sync() before any write.
Otherwise the local frames are uploaded with the wrong base index and the next
sync fails with:
server returned a conflict: sent=1, got=17
Delete the replica file before re-seeding if you have already hit this state.
Verification status
Verified live against a real Turso Cloud database during the 1.7.0 work:
bootstrap pull, journal push, remote read-back, and a clean-up DROP TABLE
through sync(). tests/Feature/TursoCloudOfflineWriteTest.php is skipped by
default in CI because no cloud credentials are available. Run it manually with:
TURSO_CLOUD_DB_URL=... TURSO_CLOUD_DB_TOKEN=... \
./vendor/bin/pest --filter=TursoCloudOfflineWriteTest
Flavor 2 — Self-hosted sqld (offline_write mode)
DB_CONNECTION=libsql
DB_DATABASE=database.sqlite
DB_AUTH_TOKEN=<token>
DB_SYNC_URL=http://127.0.0.1:8080
DB_SQLD_OFFLINE_MODE=true
DB_OFFLINE_WRITES=true
Activation: both sqldOfflineMode => true and offlineWrites => true.
Behavior: writes apply to a local write journal. DB::sync() replays the
journal to sqld. The underlying connection exposes isOnline() and
getPendingOperationsCount().
DB::sync(); // drains the pending journal
The Docker proof verifies the outage window from the host side with an independent Hrana client: sqld sees zero unsynced rows while the app is offline, then holds the exact drained rows after reconnect.
What is not supported
- Laravel 10/11.
- The Turso Cloud flavor against plain
libsql-server. It speaks the HTTPS/libSQL protocol to Turso Cloud only. - Raw
prepare()inoffline_writemode. The extension refuses it by design; the driver binds parameters and routes throughexecute()/query()instead.
Extension limitations
- Offline-write support is beta upstream in the extension itself.
- DDL (
CREATE TABLE) journals the same way as DML. syncInterval: 0disables automatic background sync in the sqld flavor; manualDB::sync()still works.
See Known Limitations and Troubleshooting for the failure signatures.