Connect LibSQL Remote Replica / Embedded Replica databases using the LibSQL PHP Extension
Tursoโs (LibSQL) embedded replicas are a game-changer for SQLite, making it more flexible and suitable for various environments. This feature shines especially for those using VMs or VPS, as it lets you replicate a Turso database right within your applications without needing to relying on Tursoโs (LibSQL) edge network. For mobile applications, where stable connectivity is a challenge, embedded replicas are invaluable as they allow uninterrupted access to the local database.
Embedded replicas provide a smooth switch between local and remote database operations, allowing the same database to adapt to various scenarios effortlessly. They also ensure speedy data access by syncing local copies with the remote database, enabling microsecond-level read operations โ a significant advantage for scenarios demanding quick data retrieval.
You configure a local file to be your main database.
url
parameter in the client configuration.You configure a remote database to sync with.
syncUrl
parameter in the client configuration.You read from a database:
url
.You write to a database:
syncUrl
.To set up a replica connection for distributed systems, the configuration need to formatted as array follow these steps:
0. Remote Turso/LibSQL Database
If you already have Turso/LibSQL Database account, do following this commands:
Get the database URL:
Get the database authentication token:
If you doesnโt have Turso/LibSQL Database Account, create one here itโs free for individual developers just getting started!
See for other plan Turso Database Pricing.
1. Defined environment variables
2. Define the configuration array with the required parameters
This configuration is designed for synchronizing and replicating data in distributed environments. It requires an array configuration with the following key-value pairs:
Specifies the local database path filename using relative path /home/turso/app/database.db
remember the back-slash at the begining.
Authentication token for secure access. Generate from Get the database authentication token command
URL for synchronization purposes. generate from Get the database URL command
Integer value representing synchronization interval in seconds (optional, default: 5
).
Boolean value indicating whether to read your writes (optional, default: true
).
String value for encryption purposes (optional, default: empty).
You should call $db->sync()
in the background whenever your application wants to sync the remote and local embedded replica. For example, you can call it every 5 minutes or every time the application starts.
Connect LibSQL Remote Replica / Embedded Replica databases using the LibSQL PHP Extension
Tursoโs (LibSQL) embedded replicas are a game-changer for SQLite, making it more flexible and suitable for various environments. This feature shines especially for those using VMs or VPS, as it lets you replicate a Turso database right within your applications without needing to relying on Tursoโs (LibSQL) edge network. For mobile applications, where stable connectivity is a challenge, embedded replicas are invaluable as they allow uninterrupted access to the local database.
Embedded replicas provide a smooth switch between local and remote database operations, allowing the same database to adapt to various scenarios effortlessly. They also ensure speedy data access by syncing local copies with the remote database, enabling microsecond-level read operations โ a significant advantage for scenarios demanding quick data retrieval.
You configure a local file to be your main database.
url
parameter in the client configuration.You configure a remote database to sync with.
syncUrl
parameter in the client configuration.You read from a database:
url
.You write to a database:
syncUrl
.To set up a replica connection for distributed systems, the configuration need to formatted as array follow these steps:
0. Remote Turso/LibSQL Database
If you already have Turso/LibSQL Database account, do following this commands:
Get the database URL:
Get the database authentication token:
If you doesnโt have Turso/LibSQL Database Account, create one here itโs free for individual developers just getting started!
See for other plan Turso Database Pricing.
1. Defined environment variables
2. Define the configuration array with the required parameters
This configuration is designed for synchronizing and replicating data in distributed environments. It requires an array configuration with the following key-value pairs:
Specifies the local database path filename using relative path /home/turso/app/database.db
remember the back-slash at the begining.
Authentication token for secure access. Generate from Get the database authentication token command
URL for synchronization purposes. generate from Get the database URL command
Integer value representing synchronization interval in seconds (optional, default: 5
).
Boolean value indicating whether to read your writes (optional, default: true
).
String value for encryption purposes (optional, default: empty).
You should call $db->sync()
in the background whenever your application wants to sync the remote and local embedded replica. For example, you can call it every 5 minutes or every time the application starts.