DIGITAL4FRONT / CODE BASE

Fix PHP pdo_kdb.so: undefined symbol file_globals_id

Diagnose KingbaseES PDO driver loading failures on Linux PHP 7.2. Identify ZTS versus NTS mismatches, inspect .so symbols and rebuild or replace incompatible extensions safely.

Share

The PHP startup warning `pdo_kdb.so: undefined symbol: file_globals_id` points to a binary compatibility problem, not a failed SQL query or a missing database password. In PHP 7.2, `file_globals_id` is defined for Zend Thread Safety (ZTS) builds, while non-thread-safe (NTS) builds use a different global. If a KingbaseES PDO extension expects the ZTS symbol but the running PHP interpreter is NTS, Linux cannot resolve the symbol when loading the extension. The preferred repair is to obtain or compile `pdo_kdb.so` for the exact PHP build you run, including its ZTS/NTS mode, PHP extension API and architecture.

What the error actually means

The dynamic loader is attempting to load a native extension and cannot find a symbol it references:

text
PHP Startup: Unable to load dynamic library 'pdo_kdb.so'
undefined symbol: file_globals_id

A shared object (`.so`) can contain references to functions and variables provided by the PHP interpreter or other libraries. Those references must resolve when the module is loaded. A missing symbol prevents startup of the extension even though PHP itself still runs.

The PHP 7.2.34 source file `ext/standard/file.c` contains the relevant distinction:

c
#ifdef ZTS
int file_globals_id;
#else
php_file_globals file_globals;
#endif

That is strong evidence of a ZTS/NTS mismatch in this case. It does not prove every other aspect of the extension is compatible. Once you resolve this first symbol, additional compatibility or dependency errors may surface. You can inspect the PHP 7.2.34 source for the file globals.

1. Confirm the PHP binary you are actually running

On a server with multiple PHP installations, `php`, `php-fpm` and the version used by the website may not be the same build. Start with the command-line interpreter that produces the warning:

bash
command -v php
php -v
php --ini
php -i | grep -E 'Thread Safety|PHP API|PHP Extension|extension_dir'

Look for `Thread Safety => disabled`. That indicates an NTS build. `enabled` indicates ZTS.

An extension directory containing `no-debug-non-zts-20170718` is also a useful clue: `non-zts` identifies the NTS mode and `20170718` identifies the PHP 7.2 extension API generation. The directory name alone, however, does not verify the binary contents of `pdo_kdb.so`.

If the extension needs to load under PHP-FPM, check that service separately. Do not assume a successful CLI test proves the web-facing PHP build is identical.

2. Check which extension file PHP tries to load

The warning normally shows the path from which PHP attempted to load the module. Compare that with the actual extension directory:

bash
php-config --extension-dir
php -i | grep '^extension_dir'
php --ini

If `php-config` is missing, inspect the configured PHP installation rather than installing an unrelated version of its development tools.

For example, PHP might look under:

text
/usr/local/lib/php/extensions/no-debug-non-zts-20170718/

But the file may have been copied into a different directory. Confirm its presence at the precise configured path before debugging symbols:

bash
ls -l /usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_kdb.so

Adjust that path to your installation. The additional `.so.so` candidate shown in some startup warnings is just another filename PHP tried. It is not the cause of an already reported undefined symbol in the real `.so` file.

A file-not-found problem and an undefined-symbol problem are different. Resolve the actual path first, then investigate compatibility.

3. Inspect the extension without executing it

Linux ELF inspection tools can show the binary architecture and unresolved symbol references. Replace the example path with the real location:

bash
EXT=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/pdo_kdb.so

file "$EXT"
readelf -h "$EXT" | grep -E 'Class:|Machine:'
readelf -Ws "$EXT" | grep 'file_globals_id'
readelf -d "$EXT" | grep NEEDED

For a 64-bit x86 server, you expect an ELF64 object built for x86-64. In the symbol listing, a line containing `UND` for `file_globals_id` indicates the extension expects that symbol from outside the module.

The `NEEDED` entries identify directly linked shared libraries. KingbaseES client libraries, such as `libkcci.so`, may also have to be available at runtime, depending on how the vendor built the driver. Missing libraries generally produce a different error and should be investigated separately.

Do not create dummy definitions of `file_globals_id` or patch the binary to make the loader continue. PHP module ABI compatibility cannot safely be repaired that way.

4. Compare the extension's build requirements with PHP

A native PHP module must match more than the major PHP version. Check these properties together:

  • **Thread-safety mode:** ZTS or NTS must match the running PHP build.
  • **PHP extension API:** A module compiled for another PHP API generation is not interchangeable.
  • **Architecture:** Both interpreter and module must target the same architecture and word size.
  • **Debug build:** Debug and non-debug builds can use incompatible module layouts.
  • **Runtime dependencies:** Required vendor client libraries and compatible system libraries must be available.

Useful local checks include:

bash
phpize -v
php-config --version
php-config --phpapi
php-config --configure-options

Run these with the development tools belonging to the same PHP installation you intend to use. If the machine has several installations, locate the matching `phpize` and `php-config` explicitly rather than relying on whichever appears first in `PATH`.

The `20170718` suffix is consistent with PHP 7.2's extension API, but matching that API is **not enough** if the shared object was compiled with ZTS enabled and PHP runs in NTS mode.

5. Preferred fix: Obtain an NTS-compatible pdo_kdb.so

When the server runs NTS PHP 7.2, the lowest-risk fix is to obtain a KingbaseES PDO driver built for the same NTS PHP release family, extension API, operating system and CPU architecture.

Ask the driver vendor or your internal package maintainer for a compatibility matrix covering the PHP version, NTS/ZTS mode, architecture and KingbaseES client-library version. Do not assume a driver described merely as 'PHP 7.2 x86_64' supports both ZTS and NTS.

After obtaining a compatible driver, install it in the correct extension directory using your normal deployment process, preserve the old file for rollback and verify the configured `extension=pdo_kdb.so` directive. Avoid copying a module from a different PHP installation solely because the filenames match.

Then run:

bash
php -m | grep -i -E 'PDO|kdb'
php --ri pdo_kdb

The exact module name reported by `php --ri` depends on the vendor's extension registration. If that command says the extension does not exist, consult `php -m`, startup warnings and the driver documentation rather than assuming the load succeeded.

6. Alternative: Rebuild the extension against the target PHP

If trustworthy driver source code is available and supports your PHP version, rebuilding it with the correct PHP headers and build tools is another option.

Inside the vendor extension source directory, the conventional native-extension build sequence is:

bash
/path/to/matching/phpize
./configure --with-php-config=/path/to/matching/php-config
make

Vendor-specific configure flags or development libraries may be required. Inspect the driver build instructions and review the compiler output. The command above is a general PHP extension build pattern, **not** a verified build recipe for KingbaseES `pdo_kdb`.

Inspect the resulting `.so` and stage a test installation before deploying it. Only install a driver that the vendor supports for your target PHP and KingbaseES versions. Refer to the PHP manual on building shared extensions with phpize.

If only a closed-source ZTS driver is supplied, you cannot convert it to NTS merely by changing `php.ini`, renaming it or moving it to an NTS extension directory.

7. Why switching PHP to ZTS is usually not the first fix

Rebuilding or installing a ZTS PHP interpreter may satisfy this particular symbol, but it is an infrastructure change with consequences for the rest of the PHP stack. Every native extension loaded by that interpreter also needs to be compatible with the ZTS build.

For legacy Unix PHP 7.2 source builds, the configure option was `--enable-maintainer-zts`. On PHP 8.0 and later, the relevant option is `--enable-zts`. ZTS is chosen when PHP is built; it is not enabled by adding an entry to `php.ini`. The PHP configure options document the version-specific names.

If you must test ZTS for a legacy dependency, build it in an isolated environment and verify the complete extension set. Do not replace a working production NTS PHP installation solely to satisfy one third-party binary without an upgrade and rollback plan.

8. Separate PHP ABI problems from KingbaseES client-library problems

Several different failures can look similar during extension installation:

text
undefined symbol: file_globals_id

This points strongly to the ZTS/NTS incompatibility described above.

text
cannot open shared object file: No such file or directory

This may mean the module itself is missing, a dependent shared library cannot be found, or the loader cannot resolve its dependency path. Inspect the precise filename in the message.

text
undefined symbol: some_other_symbol

This requires investigation of the specific missing symbol and the library expected to export it. It could indicate another ABI mismatch or an absent dependency.

Do not try to fix all three errors by blindly changing `LD_LIBRARY_PATH`. Library search paths can help locate legitimate vendor dependencies but cannot manufacture PHP's missing ZTS globals in an NTS interpreter.

Also keep the extension load failure separate from authentication and connection testing. There is no point debugging PDO connection strings until the driver loads successfully.

9. What to test after replacing the driver

First run `php -v` and `php -m` with the intended interpreter and confirm that the startup warning is gone. Then check that the driver registers with PDO:

bash
php -r 'print_r(PDO::getAvailableDrivers());'

Look for the driver identifier documented by your KingbaseES PDO package; do not assume it must be named `kdb` without checking the vendor implementation.

Only after verifying successful loading should you run a minimal database connection test using credentials obtained from protected environment configuration. Test connection behaviour separately from extension loading, and never paste connection passwords into diagnostic reports.

For production applications, confirm both CLI and PHP-FPM use the intended build and extension configuration. Keep a record of the extension checksum, vendor package version, PHP API version and thread-safety mode so the configuration can be reproduced.

10. Legacy PHP 7.2 security considerations

PHP 7.2 reached end of life on 30 November 2020 and no longer receives upstream security fixes. This article explains a legacy extension failure; it is not a recommendation to deploy a new system on PHP 7.2. See the PHP version release history for the support timeline.

If the KingbaseES driver is only available for PHP 7.2, treat that as a migration blocker to resolve with the vendor. Request a driver compatible with a currently supported PHP release or evaluate another officially supported integration method rather than retaining unsupported PHP indefinitely.

Final diagnosis

The specific `file_globals_id` error on an NTS PHP 7.2 interpreter is strong evidence that `pdo_kdb.so` was built expecting a ZTS PHP runtime. Verify the active PHP binary, its thread-safety mode, the extension API, the shared object's undefined symbols and the extension path. The preferred remedy is an NTS driver built against the matching PHP installation; rebuilding from supported source is an alternative. Changing library paths or renaming the `.so` file will not resolve this symbol mismatch.

For background, compare the PHP 7.2 source definition of `file_globals_id`, the PHP shared-extension build instructions and the PHP thread-safety configure options.

WhatsApp us