libSQL Extension for PHP Officially Landed at Turso!

libSQL Extension for PHP Officially Landed at Turso!

Hello Punk! Yes, I am again.

I’ve very busy dancing day and messing up something until I got confused (what’s going on me?!) I don’t know!

Writing bunch of paper and try to implement one by one in disorder direction (yes, it’s a tech-ni-que!) to create abstract art that make me overwhelming-confused. BTW, I just tired!

tub, I need to show you some _art_istic piece of punk by me (off course!), cz I am too handsome to do anything while dancing.


Turso Database

Turso Database

What the punk is turso?!

Nice question! Thank you very much…

Turso is a SQLite-compatible database built on libSQL, the Open Contribution fork of SQLite. It enables scaling to hundreds of thousands of databases per organization and supports replication to any location, including your own servers, for microsecond-latency access. – turso.tech

Have I just promoted Turso on my previous 3 or 4 blogs?! Hmm… damn it!

tub, never-mind! I just proud by myself found amazing playground and be the first person to build Native Extension/Driver/Whatever for PHP that support all features of Turso.

SQLite for Production

What even mean by that? It’s stupid!

Na na na na… hold on, let me tell you.

A database is often referred to as a “logical database” because it consists of multiple libSQL databases.

Each database is equipped with its own schema and data, situated in a primary location along with possibly several replica locations within its designated group. This setup ensures that the schema and data are seamlessly copied from the primary location to all replica sites in the group.

Databases are identified by a distinct libSQL URL. When accessed through the libSQL client SDKs, this URL directs the client to the database instance that offers the lowest latency, thereby reducing the overall duration of read operations.

The point I just highlight for you, this is what I called it’s is amazing place to create chaos as I can!

And you can read by your-self to proof deznutt.

Client SDKs

Lorsque je regarde le flux VimMoustache et parle de la base de données Turso, je consulte le site, je lis l’introduction et tous les concepts et fonctionnalités qu’ils ont et proposent, c’est…..

My first Impression, ThePunk! Where is PHP SDK!? Aaaaaaahhh… I am mad! tub, still handsome.

Then I search through Internet, call Vivaldi to play Campursai Music, then make a “quack” sound from the 🦆 that said: “Turso for PHP”, “libSQL for PHP” it’s basic search.

Turso for PHP

libSQL for PHP

See.. that’s me! I search the queries using browserling for fairness, btw.

Now, I am polute the Internet.

tub, before I messing up internet, they come up with nice and amazing marterpiece that represent the power of Turso. Almost all of them is implement HTTP SDK to interact with database and natively talk using SQLite3, sync using cronjob.

Then… my freestyler soul starting to stir and want to start something extraordinary with my chaos dance as a Software Freestyle Engineer (BTW).

#1 Song to Dance

I started by gathering the energy to dance by reading the documentation, comments on the source code, and exploring the libSQL repository on GitHub.

I am good as an artist

So, I will impersonate libsql-client-ts in PHP land. Yes, call me impostor for now!

You know, explore new things for me is like mountaineering, enter the forest that has not been touched much and find a way to be able to reach the top or at least be able to return home to meet the family.

I create Turso-HTTP using HTTP SDK. My first thought; this is really amazing, SQLite as Rest API?! WhatThePunk!

I am still dance with this #1 Song in 8 hours building in a loop!

After create Turso-HTTP, I think something missing here…

Ah! The Punk, yes! The sync method, tub wait… how can I implement this method in PHP when I didn’t have libSQL binary?

That question in my handsome brain, is kept coming up.

How about using Loop::addPeriodicTimer from ReactPHP and manage sync between local and remote with queue manager in JSON file with timestamp?!

Yes, I did something like this when I sell Instagram Followers, Likes, and Comments 9 years ago using mgp25/instagram-api, how wonderful that day!.

Nevermind, go back to the topic fish!

Yes, I did it! I create Turso-Syncd to leverage Turso Background Sync!

The final touch is, I support Turso-HTTP with Platform API


#2 Song to Dance

Handsome Brain Still Thinking

I need implement all features and I need to embed the libSQL Rust Binary into PHP, tub how?

Learn Rust or C damn it!

Yes! I need to learn Rust with some motivation that come from Aaron Francis podcast and YouTube Video PHP doesn’t suck (anymore)

Why not!

Learning Rust is the same as I will become rust that can stick to sturdy scrap metal.

I learn Rust! Cz libSQL build using Rust, so I can embed libSQL into my PHP Extension using crate/framework ext-php-rs made by
David Cole
this is cool crate/framework that can make people create their own PHP Extension using Rust!


Tub, I am struggle with this crate/framework in the first-time. So I decide to create using extension with On-Demand Compilation tech-ni-que “this sound stupid” using Rust Cbindgen, so I force developer to build this extension from Source via Composer it’s called libsql-php-ext!

So, when you run this command:

composer require darkterminal/libsql-php-ext
Enter fullscreen mode
Exit fullscreen mode

They will install:

  • C/C++ Compiler
  • jq
  • Rust Installed
  • PHP Installed
  • FFI Extension is Enabled (Why? I read the C heder definition from wrapper)

Then create PHP Abstraction to wrap the API in PHP using PHP FFI. It’s too complicated like Tech’s nowaday 😁, I named libSQL Client PHP and this is the #1 libSQL PHP binary that talk natively with libSQL driver!

And I think this is too forced and less effective for working in a PHP environment because developers have to build it from source with various tool preparations. Why not make it a binary file that can be downloaded and used immediately like a PHP extension in general?!


#3 Song to Dance

Handsome Dance Move

Now I’m starting to get familiar with the ext-php-rs crate/framework to start creating libSQL extensions for PHP after a few tries.

Like penetrating a wild jungle in the mountains without a compass and without experience, yes, this was indeed my first journey dancing in a new language sung and accompanied by rusty old iron music.

After <1 Month! I create libSQL Native Extension for PHP that support all Turso features! And distribute the extension via GitHub Action!

There is no other song, tub if you want to hear more about Campursari Song Playlist while creating the libSQL Native Extension for PHP Turso for PHP – Building Playlists

Native BTW

libSQL Native Extension for PHP

One-time installation for your PHP Environment and use it anywhere in your PHP project!

I build and make it feel like using SQLite3 in PHP but powered by more type of database connections!

  • In-Memory Connection
  • Local Connection
  • Remote Connection ✅
  • Embedded Replica ✅

This this the core features of Turso/libSQL and it’s now available for PHP!

The Extension Repository:

The Other PHP Driver Repostories:

Officially Landed

The landing page for PHP

The landing page for PHP at Turso: https://turso.tech/php

Made in Java

This is amazing joke from CEO of Turso Database! Don’t get angry because of this, THIS IS A JOKE!

Made in Java

Source: Tweet from Glauber Costa – Founder/CEO at Turso Database


You can support my open-source activity at GitHub and support me to keep build something that make me proud of myself!

Become a Sponsor


Discover more from Coursity

Subscribe to get the latest posts to your email.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *