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

', + esc_html__( 'The SQLite Integration plugin requires 64-bit PHP. Please switch to a 64-bit PHP installation before enabling SQLite.', 'sqlite-database-integration' ) + ); + return; + } + // Bail early if the pdo_sqlite extension is not loaded. if ( ! extension_loaded( 'pdo_sqlite' ) ) { printf( diff --git a/packages/plugin-sqlite-database-integration/admin-page.php b/packages/plugin-sqlite-database-integration/admin-page.php index 8f833f496..a3f19ce65 100644 --- a/packages/plugin-sqlite-database-integration/admin-page.php +++ b/packages/plugin-sqlite-database-integration/admin-page.php @@ -66,6 +66,10 @@ function sqlite_integration_admin_screen() { ); ?>

+ +
+

+

diff --git a/packages/plugin-sqlite-database-integration/composer.json b/packages/plugin-sqlite-database-integration/composer.json index d77c7f478..254aa1c85 100644 --- a/packages/plugin-sqlite-database-integration/composer.json +++ b/packages/plugin-sqlite-database-integration/composer.json @@ -9,6 +9,7 @@ }, "require": { "php": ">=7.2", + "php-64bit": "*", "ext-pdo": "*", "ext-pdo_sqlite": "*" } diff --git a/packages/plugin-sqlite-database-integration/readme.txt b/packages/plugin-sqlite-database-integration/readme.txt index 06c5cf2ca..46a238351 100644 --- a/packages/plugin-sqlite-database-integration/readme.txt +++ b/packages/plugin-sqlite-database-integration/readme.txt @@ -28,7 +28,7 @@ The plugin replaces the default MySQL database layer with an SQLite-backed imple **Important:** Enabling SQLite creates a separate, empty database; it does not migrate an existing site. If you enable it on a site that uses MySQL or MariaDB, WordPress will ask you to set up the site again. Disabling the plugin reconnects WordPress to the previous database with its data unchanged. Changes made while using SQLite are not transferred. -The plugin requires the PDO SQLite PHP extension and SQLite 3.37.0 or newer. +The plugin requires 64-bit PHP with the PDO SQLite extension and SQLite 3.37.0 or newer. == Frequently Asked Questions == @@ -75,7 +75,7 @@ The value of `DB_PATH` must be an absolute path to the SQLite database file, or = What does the plugin require? = -In addition to the WordPress and PHP versions listed above, the plugin requires the PDO SQLite PHP extension and SQLite 3.37.0 or newer. The setup screen also needs write access to the `wp-content` directory and will detect conflicting database drop-ins. +In addition to the WordPress and PHP versions listed above, the plugin requires 64-bit PHP with the PDO SQLite extension and SQLite 3.37.0 or newer. The setup screen also needs write access to the `wp-content` directory and will detect conflicting database drop-ins. = Where can I submit my plugin feedback? = diff --git a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php index fb5de2b67..2fb3e1929 100644 --- a/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php +++ b/packages/plugin-sqlite-database-integration/wp-includes/sqlite/db.php @@ -17,6 +17,10 @@ return; } + if ( PHP_INT_SIZE < 8 ) { + throw new RuntimeException( 'The SQLite Integration plugin requires 64-bit PHP.' ); + } + if ( ! extension_loaded( 'pdo' ) ) { wp_die( new WP_Error(