diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 67b744fa0..d92610f10 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -26,6 +26,18 @@ concurrency: permissions: {} jobs: + test-32-bit-php: + name: Reject 32-bit PHP + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + - run: | + docker run --rm --platform linux/386 -v "$PWD:/repo:ro" -w /repo \ + php:8.3-cli php packages/mysql-on-sqlite/tests/32-bit-php.php + test: name: PHP ${{ matrix.php }} / SQLite ${{ matrix.sqlite }} runs-on: ubuntu-latest diff --git a/AGENTS.md b/AGENTS.md index 59a4fc601..ddd4295e9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -24,9 +24,9 @@ The monorepo packages are placed under the `packages` directory. The WordPress plugin links the MySQL on SQLite package using a symlink. The build script replaces the symlink with a copy of the package for release. -The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6, -MySQL syntax from version 5.7 onward, and requires SQLite 3.37.0 or newer -(with legacy mode down to 3.27.0). +The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6 +and MySQL syntax from version 5.7 onward. The SQLite driver requires 64-bit PHP +and SQLite 3.37.0 or newer (with legacy mode down to 3.27.0). ## Commands The codebase is written in PHP and Composer is used to manage the project. diff --git a/README.md b/README.md index 9eff93f29..d5b333b89 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ The monorepo packages are placed under the `packages` directory. The WordPress plugin links the MySQL on SQLite package using a symlink. The build script replaces the symlink with a copy of the package for release. -The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6, -MySQL syntax from version 5.7 onward, and requires SQLite 3.37.0 or newer -(with legacy mode down to 3.27.0). +The codebase is pure PHP with zero dependencies. It supports PHP 7.2 through 8.6 +and MySQL syntax from version 5.7 onward. The SQLite driver requires 64-bit PHP +and SQLite 3.37.0 or newer (with legacy mode down to 3.27.0). ## Quick start The codebase is written in PHP and Composer is used to manage the project. diff --git a/composer.json b/composer.json index 348419869..e64885578 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ }, "require": { "php": ">=7.2", + "php-64bit": "*", "ext-pdo": "*", "ext-pdo_sqlite": "*" }, diff --git a/packages/mysql-on-sqlite/README.md b/packages/mysql-on-sqlite/README.md index 2ffa3cff1..565547af7 100644 --- a/packages/mysql-on-sqlite/README.md +++ b/packages/mysql-on-sqlite/README.md @@ -133,7 +133,7 @@ composer run test -- --filter testName ## Requirements -- **PHP:** 7.2+ +- **PHP:** 7.2+ (64-bit) - **PHP extensions:** `pdo`, `pdo_sqlite` - **SQLite:** 3.37.0+ diff --git a/packages/mysql-on-sqlite/composer.json b/packages/mysql-on-sqlite/composer.json index 8ede2dcb0..e9edb44b6 100644 --- a/packages/mysql-on-sqlite/composer.json +++ b/packages/mysql-on-sqlite/composer.json @@ -17,6 +17,7 @@ }, "require": { "php": ">=7.2", + "php-64bit": "*", "ext-pdo": "*", "ext-pdo_sqlite": "*" }, diff --git a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php index 1e9053e18..ad9fb4b8c 100644 --- a/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php +++ b/packages/mysql-on-sqlite/src/sqlite/class-wp-mysql-on-sqlite.php @@ -35,7 +35,7 @@ trait WP_MySQL_On_SQLite_PDO_Compat {} * It translates queries written in MySQL SQL dialect to an SQLite SQL dialect, * maintains necessary metadata, and executes the translated queries in SQLite. * - * The driver requires PDO with the SQLite driver, and the PCRE engine. + * The driver requires 64-bit PHP, PDO with the SQLite driver, and the PCRE engine. */ class WP_MySQL_On_SQLite extends PDO { use WP_MySQL_On_SQLite_PDO_Compat; @@ -135,9 +135,6 @@ class WP_MySQL_On_SQLite extends PDO { 'HIGH_NOT_PRECEDENCE' => 1 << 29, 'NO_ENGINE_SUBSTITUTION' => 1 << 30, 'PAD_CHAR_TO_FULL_LENGTH' => 1 << 31, - - // Modes below require 64-bit PHP. - // TODO: Consider supporting these values on 32-bit PHP as well. 'TIME_TRUNCATE_FRACTIONAL' => 1 << 32, ); @@ -810,6 +807,10 @@ public function __construct( ?string $password = null, ?array $options = null ) { + if ( PHP_INT_SIZE < 8 ) { + throw $this->new_driver_exception( 'The MySQL on SQLite driver requires 64-bit PHP.' ); + } + $options = $options ?? array(); // PDO DSN can't include "\0" bytes; parsing stops at the first one. diff --git a/packages/mysql-on-sqlite/tests/32-bit-php.php b/packages/mysql-on-sqlite/tests/32-bit-php.php new file mode 100644 index 000000000..15bda6a19 --- /dev/null +++ b/packages/mysql-on-sqlite/tests/32-bit-php.php @@ -0,0 +1,24 @@ +getMessage() ) { + throw $e; + } +} + +if ( file_exists( $path ) ) { + throw new RuntimeException( 'The driver created a database file on 32-bit PHP.' ); +} diff --git a/packages/plugin-sqlite-database-integration/README.md b/packages/plugin-sqlite-database-integration/README.md index 756ed167b..a995edf29 100644 --- a/packages/plugin-sqlite-database-integration/README.md +++ b/packages/plugin-sqlite-database-integration/README.md @@ -83,7 +83,7 @@ The archive is written to `build/plugin-sqlite-database-integration.zip`. ## Requirements - **WordPress:** 6.4+ -- **PHP:** 7.2+ +- **PHP:** 7.2+ (64-bit) - **PHP extensions:** `pdo`, `pdo_sqlite` - **SQLite:** 3.37.0+ diff --git a/packages/plugin-sqlite-database-integration/activate.php b/packages/plugin-sqlite-database-integration/activate.php index 2274dd1c6..d268a9c7b 100644 --- a/packages/plugin-sqlite-database-integration/activate.php +++ b/packages/plugin-sqlite-database-integration/activate.php @@ -71,8 +71,7 @@ function ( $result ) { * When the plugin gets merged in wp-core, this is not to be ported. */ function sqlite_plugin_copy_db_file() { - // Bail early if the pdo_sqlite extension is not loaded. - if ( ! extension_loaded( 'pdo_sqlite' ) ) { + if ( PHP_INT_SIZE < 8 || ! extension_loaded( 'pdo_sqlite' ) ) { return; } diff --git a/packages/plugin-sqlite-database-integration/admin-notices.php b/packages/plugin-sqlite-database-integration/admin-notices.php index fb440d62d..71d3e489d 100644 --- a/packages/plugin-sqlite-database-integration/admin-notices.php +++ b/packages/plugin-sqlite-database-integration/admin-notices.php @@ -19,6 +19,14 @@ function sqlite_plugin_admin_notice() { return; } + if ( PHP_INT_SIZE < 8 ) { + printf( + '
%s