rfc:mysqli_support_for_libmysql

PHP RFC: Remove support for libmysql from mysqli

At the moment both mysqli and PDO_mysql support building against mysqlnd and libmysql. The default is mysqlnd since PHP 5.4. Mysqlnd is the recommended driver to be used with PHP.

Introduction

There are plenty of differences between the two drivers. Removing support for libmysql would allow PHP to simplify the code and unit tests. Advantages of mysqlnd include:

  • Bundled with PHP
  • Uses PHP memory management which helps to monitor memory usage and
  • improve performance
  • Provides functions that make life easier, e.g. get_result
  • Returns numeric values using PHP native types
  • The functionality does not depend on the version of the external library
  • Optional plugin functionality
  • Asynchronous queries

Advantages of libmysql:

  • Auto-reconnect is possible (this functionality is intentionally not supported by mysqlnd due to how dangerous it is)
  • LDAP and SASL authentication modes A PR exists to add this functionality to mysqlnd

However, libmysql has many disadvantages:

  • It does not use PHP memory model. It doesn't respect the memory limits, does not count towards memory stats and cannot utilize internal optimizations
  • PHP does not know the value size and needs to allocate as much memory as the field length. This makes it very difficult to use with long columns like LONGTEXT
  • Doesn't support get_result, bind-in-execute, and fetch_all & next_result (prior to PHP 8.1). This makes libmysql the smallest common denominator for applications like DBALs which can't rely on these easy to use functions and instead have to perform strange workarounds resulting in more complex code and worse performance, even when not using libmysql
  • Functionality differs from version to version. Depending on which libmysql version PHP was compiled with you might be able to use a certain feature or not.
  • Many failing tests. Some of these tests could be fixed with SKIP or conditional checks, but some fail because of incompatibilities.
  • Memory leaks. These might even be considered security vulnerabilities
  • Not available on Windows

While many distributions offer PHP with mysqlnd as default there are some that make it confusing for new users. In particular, when using cPanel, users are confused about how to enable mysqli with mysqlnd. Instead of enabling mysqli they have to enable nd_mysqli extension which is counterintuitive.

Making it possible to build mysqli against external libraries with limited functionality is confusing and unnecessary.

Proposal

The proposal is to remove the support for building mysqli against libmysql in the next version. As mysqlnd is the default option, most users should not observe any difference.

As of PHP 8.2, it will not be possible to link mysqli against any version of libmysql. If the option --with-mysqli will be supplied, mysqli will be built with mysqlnd.

Backward Incompatible Changes

It will not be possible to build mysqli against libmysql anymore. Any functionality that was only available with libmysql will have to be added to mysqlnd as a feature request. We will not add auto-reconnect, which means that users relying on this feature will have to find other ways.

Proposed PHP Version(s)

The change is proposed to go into PHP 8.2.

RFC Impact To Existing Extensions

Only mysqli extension will be affected.

Unaffected PHP Functionality

PDO_MySQL and PECL-mysql are not affected and can still be compiled against both drivers.

The PHP native driver (mysqlnd) will still be mostly compatible with libmysql and no further divergence in functionality is foreseen to happen.

Future Scope

This RFC does not deal with libmysql support in PDO_MySQL, although it might also be removed in future. At the moment, there are no arguments speaking against it.

Proposed Voting Choices

Voting started on 2022-01-22 and ends on 2022-02-05.

Remove support for libmysql from mysqli
Real name Yes No
alec (alec)  
asgrim (asgrim)  
ashnazg (ashnazg)  
cmb (cmb)  
cpriest (cpriest)  
crell (crell)  
cschneid (cschneid)  
dharman (dharman)  
gasolwu (gasolwu)  
geekcom (geekcom)  
girgias (girgias)  
irker (irker)  
jbnahan (jbnahan)  
jhdxr (jhdxr)  
kalle (kalle)  
kguest (kguest)  
kocsismate (kocsismate)  
marandall (marandall)  
mauricio (mauricio)  
mbeccati (mbeccati)  
ocramius (ocramius)  
patrickallaert (patrickallaert)  
reywob (reywob)  
santiagolizardo (santiagolizardo)  
sebastian (sebastian)  
sergey (sergey)  
svpernova09 (svpernova09)  
theodorejb (theodorejb)  
tstarling (tstarling)  
twosee (twosee)  
Final result: 30 0
This poll has been closed.

Patches and Tests

References

rfc/mysqli_support_for_libmysql.txt · Last modified: 2022/05/30 16:09 by dharman