• Search:



Planet eZ publish




derick rethans

› Not Finding the Symbols

Not Finding the Symbols

Yesterday we released the new version of the MongoDB Driver for PHP, to coincide with the release of MongoDB 3.4. Not long after that, we received an issue through GitHub titled "Undefined Symbol php_json_serializable_ce in Unknown on Line 0".

TL;DR: Load the JSON extension before the MongoDB extension.

The newly released version of the driver has support for PHP's json_encode() through the JsonSerializable interface, to convert some of our internal BSON types (think MongoDB\BSON\Binary and MongoDB\BSON\UTCDateTime) directly to JSON. For this it uses functionality in PHP's JSON extension, and with that the php_json_serializable_ce symbol that this extension defines.

We run our test suite on many different distributions, but (nearly) always with our own compiled PHP binaries as we need to support so many versions of PHP (5.4-5.6, 7.0, and now 7.1), in various configurations (ZTS, or not; 32-bit or 64-bit). It came hence quite as a surprise that a self-compiled extension would not load for one of our users.

When compiling PHP from its source, by default the JSON extension becomes part of the binary. This means that the JSON extension, and the symbols it implements are always available. Linux distributions often split out each extension into their own package or shared object. Debian has php5-json (on which php5-cli depends), while Fedora has php-json. In order to make use of the JSON extension, you therefore need to install a separate package that provides the shared object (json.so) and a configuration file. Fedora installs the 20-json.ini file in /etc/php.d/. Debian installs the 20-json.ini file in /etc/php5/mods-available with a symlink to /etc/php5/cli/conf.d/20-json.ini. In both cases, they include the required extension=json.so line that instruct PHP to load the shared object and make its symbols (and PHP functions) available.

A normal PHP binary uses the dlopen system call to load a shared object, with the RTLD_LAZY flag. This flag means that symbols (such as php_json_serializable_ce) are only resolved lazily, when they are first used. This is important, because PHP extensions and the shared objects they live in, can depend on each other. The MongoDB extension depends on date, spl and json. After PHP has loaded all the shared extensions, it registers the classes and functions contained in them, in an order to satisfy this dependency graph. PHP makes sure that the classes and functions in the JSON extension are registered before the MongoDB extension, so that when the latter uses the php_json_serializable_ce symbol to declare that the MongoDB\\BSON\\UTCDateTime class implements the JsonSerializable interface the symbol is already available.

Distributions often want to harden their provided packages with additional security features. For that, they compile binaries with additional features and flags.

Debian patches PHP to replace the RTLD_LAZY flag with RTLD_NOW. Instead of resolving symbols when they are first used, this signals to the dlopen system call to resolve the symbols when the shared object is loaded. This means, that if the MongoDB extension is loaded before the JSON extension, the symbols are not available yet, and the linker throws the "Undefined Symbol php_json_serializable_ce in Unknown on Line 0" error from our bug report. This is not a problem that only related to PHP; TCL has similar issues for example.

With Fedora, the same issue is present, but shows through slightly different means. Instead of patching PHP to replace RTLD_LAZY with RTLD_NOW, it uses linker flags ("-Wl,-z,relro,-z,now") to force binaries to resolve symbols as soon as they are loaded process wide. This Built with BIND_NOW security feature goes hand in hand with Built with RELRO. The explanation on why these features are enabled on Fedora is well described on their wiki. Previously, this did expose an issue with an internal PHP API regarding creating a DateTime object.

But where does this leave us? The solution is fairly simple: You need to make sure that the JSON extension's shared object is loaded before the MongoDB extension's shared object. PECL's pecl install suggests to add the extension=mongodb.so line to the end of php.ini. Instead, on Debian, it would be much better to put the extension=mongodb.so line in a separate 99-mongodb.ini file under /etc/php5/mods-available, with a symlink to /etc/php5/cli/conf.d/99-mongodb.ini. Make sure you do the same for configuration directories for Apache. On Fedora, you should add the extension=mongodb.so line to the new file /etc/php.d/50-mongodb.ini.

Alternatively, you can install the distribution's package for the MongoDB extension. Fedora currently has the updated 1.2.0 release for Rawhide (Fedora 26). Debian however, does not yet provide a package for the latest release yet, although an older version (1.1.7) is available in Debian unstable. At the time of this writing, Ubuntu only provides older versions for Xenial and Yakkety.

30/11/2016 3:55 pm (UTC)   Derick Rethans   View entry   Digg!  digg it!   del.icio.us  del.icio.us

mugo web

› Building an accessible website: How to create accessible forms

Forms are an integral part of many websites and pose unique challenges related to making these interactive elements accessible to all users. 

29/11/2016 7:44 pm (UTC)   Mugo Web   View entry   Digg!  digg it!   del.icio.us  del.icio.us

mugo web

› Building an accessible website: How to create accessible forms

Forms are an integral part of many websites and pose unique challenges related to making these interactive elements accessible to all users. 

29/11/2016 7:44 pm (UTC)   Mugo Web   View entry   Digg!  digg it!   del.icio.us  del.icio.us

mugo web

› Building an accessible website: Writing accessible alt tags for images

Creating alt tags that conform to Web Content Accessibility Guidelines (WCAG) ensures all of your readers can have access to your website's images. Here's a look at how to create effective alt tags for accessibility.

28/11/2016 7:20 pm (UTC)   Mugo Web   View entry   Digg!  digg it!   del.icio.us  del.icio.us

mugo web

› Building an accessible website: Writing accessible alt tags for images

Creating alt tags that conform to Web Content Accessibility Guidelines (WCAG) ensures all of your readers can have access to your website's images. Here's a look at how to create effective alt tags for accessibility.

28/11/2016 7:20 pm (UTC)   Mugo Web   View entry   Digg!  digg it!   del.icio.us  del.icio.us

netgen

› Announcing Web Summer Camp 2017! Speakers Wanted

We at Netgen and Salsa Adria Productions are ready for another #websc adventure, are you? :) The website is out, we know the time and the place, and are looking for speakers and sponsors. We've also released all 2016 PHP and eZ Publish workshop videos, check them out!

24/11/2016 10:56 am (UTC)   http://www.netgenlabs.com/Blog   View entry   Digg!  digg it!   del.icio.us  del.icio.us

ez publish community gateway

› The Week in Review: Security Advisory, Platform.sh Developer Worfkflow, and More

This week brings us a look ahead to SymfonyCon Berlin, a follow up on developing on eZ Platform on Platform.sh, a gift from Kaliop, and lots more.

18/11/2016 6:56 pm (UTC)   http://share.ez.no   View entry   Digg!  digg it!   del.icio.us  del.icio.us

ez publish community gateway

› Persistence caching with memcache in eZ Publish 5.x and eZ Platform

In eZ Publish 5.x and eZ Platform, the concept of "view cache" has changed. The "module result" part of it (which was basically page-level caching if we didn't count the pagelayout) has been offloaded to HTTP caching, most often implemented with Varnish. In addition, Cache blocks no longer exist and have been replaced by ESI (Edge Side Includes) blocks.

The persistence caching element -- that is, caching of your actual content from the database -- of the "view cache" still exists, handled by default on the file system through the Stash bundle. Stash also supports memcache (which, as its name suggests, uses memory, and has a much better performance). We use memcache(d) for all of our production sites.

14/11/2016 6:51 pm (UTC)   http://share.ez.no   View entry   Digg!  digg it!   del.icio.us  del.icio.us

ez publish community gateway

› eZ Community Board meeting, October 20, 2016

Here are the minutes of the latest Community Board meeting, October 20, 2016. Our previous minutes can be found here.

11/11/2016 7:30 pm (UTC)   http://share.ez.no   View entry   Digg!  digg it!   del.icio.us  del.icio.us

ez publish community gateway

› The Week in Review: eZ Platform Voted Best Enterprise CMS, Community Board Updates and More

This week brings us exciting news, as eZ Platform won the CMS Critic 2016 award for Best Enterprise CMS. We also saw the first crowdfunding campaign by Netgen, for the Tag Bundle. And we have updates from the Community Board.

11/11/2016 6:04 pm (UTC)   http://share.ez.no   View entry   Digg!  digg it!   del.icio.us  del.icio.us