Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: Support to Thread Safe builds #6

Open
harrysbaraini opened this issue Jul 16, 2024 · 12 comments
Open

[Feature Request]: Support to Thread Safe builds #6

harrysbaraini opened this issue Jul 16, 2024 · 12 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@harrysbaraini
Copy link

Description

Hello, first of all, thank you for such great work.

I'm trying to get it working with FrankenPHP (that uses thread safe builds) but Turso php client seems to be built with PHP NTS. For that reason, I get PHP Warning: PHP Startup: Unable to load dynamic library error.

I cloned this repo locally but I have almost zero knowledge on rust. Guidance or support to it would be appreciated. I'm evaluating Turso for a new enterprise application, but I'd like to stitch with Franken too for its Mercury feature as well.

Thank you.

Describe the solution you'd like

I'm on a Macbook M2. I'm updated Dockerfile to use php:8.3-zts as the base docker image, but when running cross build ... I get this error: could not create home directory: '/.rustup': Permission denied (os error 13). I tried setting up RUSTUP_HOME on host but it didn't work as well.

Describe alternatives you've considered

No response

@harrysbaraini harrysbaraini added the enhancement New feature or request label Jul 16, 2024
@darkterminal
Copy link
Collaborator

darkterminal commented Jul 16, 2024

Hi @harrysbaraini, thank you for using this extension. What's file you add in your php.ini is a .dylib or .so file?

I never used frankenphp, can you provide a more detailed explanation of how you did the configuration?

FYI: this extension is not using PDO driver.

@harrysbaraini
Copy link
Author

I am on phone now, so sorry for not much detail. I followed the instructions in Readme and added the so extension to my ini.

As soon as I get back to my laptop I'll give a bit more detail.

@darkterminal
Copy link
Collaborator

Oki...

@harrysbaraini
Copy link
Author

@darkterminal I just have a simple Dockerfile, where I download the compiled extension and add it to php.ini.

FROM composer
FROM dunglas/frankenphp:1.2-php8.3

COPY --from=composer /usr/bin/composer /usr/bin/composer

RUN install-php-extensions \
    intl \
    pdo_mysql \
    pdo_pgsql \
    zip \
    redis \
    pcntl \
    posix

RUN apt update && \
    apt install -yq ca-certificates wget unzip npm && \
    rm -rf /var/cache/apt/* /tmp/*

RUN wget https://github.com/tursodatabase/turso-client-php/releases/download/turso-php-extension-v1.2.6/libsql_php-turso-php-extension-v1.2.6-php-8.3-x86_64-unknown-linux-gnu.tar.gz \
    && tar -xf libsql_php-turso-php-extension-v1.2.6-php-8.3-x86_64-unknown-linux-gnu.tar.gz \
    && mv libsql_php-turso-php-extension-v1.2.6-php-8.3-x86_64-unknown-linux-gnu/liblibsql_php.so $(php -i | grep ^extension_dir | cut -d " " -f 5) \
    && echo "extension=liblibsql_php.so" > /usr/local/etc/php/conf.d/liblibsql_php.ini \
    && rm -rf libsql_php-turso-php-extension-v1.2.6-php-8.3-x86_64-unknown-linux-gnu \
    && rm -f libsql_php-turso-php-extension-v1.2.6-php-8.3-x86_64-unknown-linux-gnu.tar.gz

WORKDIR /app

php -i output:

Warning: PHP Startup: libsql_php: Unable to initialize module
Module compiled with build ID=API20230831,NTS
PHP    compiled with build ID=API20230831,TS
These options need to match
 in Unknown on line 0
[PHP Modules]
Core
ctype
curl
[...]

Meanwhile, I'll try to compile FrankenPHP without thread-safety so I can evaluate Turso. It will work but with some drawbacks (dunglas/frankenphp#601 (comment)).

I'll still keep trying to compile this library locally, and if works I can happily open a PR.

@darkterminal
Copy link
Collaborator

Thank you for your report! I will try to compile this using PHP NTS. But you can also create PR if you want.

@harrysbaraini
Copy link
Author

It looks like it's already compiled as NTS, in this case it should be compiled with Thread-Sagety enabled I think.

Thank you!

@harrysbaraini
Copy link
Author

I tried to find some guidance in README or a Contributing.md but didn't find it. Could you briefly explain how do you compile?

I have rust and cross installed in my macbook. I then run cross build --release --target x86_64-unknown-linux-gnu but I get could not create home directory: '/.rustup': Permission denied (os error 13. RUSTUP_HOME is set accordingly to $HOME/.rustup.

@darkterminal
Copy link
Collaborator

@andersonpem
Copy link

FrankenPHP gives me:

447.3  TURSO CLIENT PHP SUCCESSFULLY INSTALLED!
447.3  To get extension class autocompletion you need to modify your IDE Settings
447.3  in this case VSCode Settings:
447.3  - Open your VSCode setting (cmd/ctrl+,) then search "intelephense.stubs"
447.3  - add this: /root/.turso-client-php value on the lists
447.3  Thank you for using Turso Database!
447.3 
447.3 + echo extension=/root/.turso-client-php/liblibsql_php.so
447.3 + php -m
447.3 + grep -q libsql
447.3 PHP Warning:  PHP Startup: libsql_php: Unable to initialize module
447.3 Module compiled with build ID=API20230831,NTS
447.3 PHP    compiled with build ID=API20230831,TS
447.3 These options need to match
447.3  in Unknown on line 0

PHP compiled for FrankenPHP is Thread Safe :)

@darkterminal
Copy link
Collaborator

darkterminal commented Sep 2, 2024

@andersonpem It seems that the error generated occurs because the PHP version used is different from the downloaded binary.

Btw, I never used FrankenPHP before.

@andersonpem
Copy link

For setting up the shivammathur/setup-php@v2 with thread safe PHP, go:

jobs:
  run:
    runs-on: ubuntu-latest
    name: Setup PHP TS
    steps:
    - name: Setup PHP
      uses: shivammathur/setup-php@v2
      with:
        php-version: '8.3'
      env:
        phpts: ts # specify ts or nts

@darkterminal darkterminal added good first issue Good for newcomers help wanted Extra attention is needed labels Sep 6, 2024
@darkterminal
Copy link
Collaborator

Hi folk! Btw, I planned to adding some commands that might be very helpful for installing this extension in a non-interactive environment, like:

Description:
  Install Turso libSQL Extension for PHP

Usage:
  install [options]

Options:
  -y, --yes                                Skip interactive installation process
      --php-version[=PHP-VERSION]          Define your chosen PHP Version: 8.0, 8.1, 8.2, 8.3 default: Your Current PHP Version
      --php-ini-file[=PHP-INI-FILE]        Define your PHP INI file location: eg: /etc/php/<version>/cli/php.ini default: /etc/php/<version>/cli/php.ini
      --ext-destination[=EXT-DESTINATION]  Define your PHP Extension Destination: eg: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/ default: /usr/local/lib/php/extensions/no-debug-non-zts-20190902/
Option Purpose Default Behavior Example
-y, --yes Skip interactive prompts. Interactive mode is enabled. install --yes
--php-version Specify the PHP version for the extension. Current PHP version is detected. install --php-version=8.1
--php-ini-file Specify the php.ini file location. Default file based on PHP version, e.g., /etc/php//cli/. install --php-ini-file=/etc/php/8.0/cli/php.ini
--ext-destination Specify the directory where the extension will be installed. Default PHP extension directory. install --ext-destination=/usr/local/lib/php/extensions/custom-directory/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants