Hi Internals,

I would like to propose dropping support for libmysql from mysqli and ask
for opinions on how this could be best achieved.

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 library to be used with PHP.

There are plenty of differences between the two libraries. 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)

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.

In 2019, Nikita suggested dropping the support or finding a maintainer for
it [1]. So far, nobody has come forth to improve mysqli support with
libmysql. It has become clear that there is not much demand for it. If
people were using it, then someone would eventually fix the bugs. PHP
doesn't have CI jobs and is not testing for the failing unit tests. We can
consider mysqli with libmysql as not supported configuration, but that
leaves us with the problem that PHP still makes it possible to compile with
libmysql and the PHP manual list it as a viable option.

I would propose to drop the support for mysqli with libmysql, but it would
be nice to do it with a deprecation period. I am not sure if it is possible
to have a deprecation period. If we raise a deprecation during compilation,
users won't see it. If we raise it during usage, we will flood their error
logs.

I think we can keep support for libmysql with PDO_mysql as it has been
fixed and seems to be working ok. I am not sure what benefit it brings, but
if it doesn't harm then there's probably no reason to drop it. Certainly,
we should encourage usage of mysqlnd with PDO as it should offer better
performance and reliability. We don't control the version of libmysql used
in the compilation process so while it works in CI jobs, it might not work
100% when used with other versions. e.g. MySQL's libmysql vs MariaDB's
libmysql

I am also looking to find out if anyone knows of any other advantages of
mysqli with libmysql or is intentionally using mysqli with libmysql in
their production systems.

[1]: https://externals.io/message/106086

Further reading:
https://externals.io/message/55084

Kind Regards,
Kamil Tekiela

Reply via email to