Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Derick Rethans:
Using the Right Debugging Tools
Oct 10, 2018 @ 14:47:42

Derick Rethans has a new post with his own suggestion about using the right debugging tools to help track down a problem (based on some of his own experience debugging the MongoDB PHP extension).

A while ago, we updated the MongoDB PHP driver's embedded C library to a new version. The C library handles most of the connection management and other low level tasks that the PHP driver needs to successfully talk to MongoDB deployments, especially in replicated environments where servers might disappear for maintenance or hardware failures.

After upgrading a related library, he ended up with a failing test related to Atlas connectivity. He walks through the process he took to try and debug the issue using GDB to see where the execution was failing using various techniques. This included looking through the backtrace and, not noticing anything out of the ordinary, going for a walk. Upon returning he noticed an odd line in the backtrace that, after some additional tracking using a GDB helper, showed the problem to be with how the query options are defined and not reset in a loop.

tagged: debugging tools gdb mongodb driver backtrace execution

Link: https://derickrethans.nl/debugging-with-tools.html

TutsPlus.com:
How to Create a Custom Authentication Guard in Laravel
Nov 10, 2017 @ 17:53:25

In the TutsPlus.com site there's a tutorial posted showing you how to create a custom guard in Laravel by building on top of the current system to integrate it with a MongoDB database.

In this article, we’re going to cover the authentication system in the Laravel framework. The main aim of this article is to create a custom authentication guard by extending the core authentication system.

Laravel provides a very solid authentication system in the core that makes the implementation of basic authentication a breeze. [...] Moreover, the system itself is designed in such a way that you could extend it and plug in your custom authentication adapters as well. That’s what we'll discuss in detail throughout this article.

The article then starts out with a brief description of the two parts of the system: "guards" and "providers". It then provides the list of files that will be involved and where they belong in the overall structure. From there it's on to the configuration changes and code required to make the link to the MongoDB database and the creation of the User model and authentication provider. Next comes the code to create the guard and what's required to tie it all together and make the full system work. The tutorial wraps up with an example of testing this new guard via a simple controller call.

tagged: laravel tutorial guard authentication user framework mongodb

Link: https://code.tutsplus.com/tutorials/how-to-create-a-custom-authentication-guard-in-laravel--cms-29667

Derick Rethans:
New Date/Time Support in MongoDB
Aug 15, 2017 @ 14:46:11

In a new post to his site Derick Rethans talks about the new DateTime support in MongoDB and includes some PHP examples showing the changes in action.

In the past few months I have been working on adding time zone support to MongoDB's Aggregation Framework. This support brings in the timelib library that is also used in PHP and HHVM to do time zone calculations.

He then splits the rest of the post up into parts for the changes that this integration brings:

  • Time Zone Support for Date Extraction Operators
  • The $dateToParts Operator
  • The $dateFromParts Operator
  • Changes to the $dateToString Operator
  • The $dateFromString Operator
  • Using Date Expressions in $match

The post ends with a few notes about these changes, noting that it's currently only in the development release and "should be considered experimental" and subject to change. He then points out a few issues that will probably require updates to these features.

tagged: datetime support mongodb example tutorial list

Link: https://derickrethans.nl/mongo-date-time.html

Derick Rethans:
HHVM and MongoDB
May 31, 2017 @ 16:56:50

Derick Rethans has a post on his site with an update about the MongoDB driver for HHVM - mostly that, because of feedback he received, it will no longer be maintained.

At the start of 2015 we began work on an HHVM driver for MongoDB, as part of our project to renew our PHP driver. Back then, HHVM was in its ascendancy and outperforming PHP 5.6 two to one. With such a huge performance difference it was reasonable to assume that many users would be switching over.

[...] With PHP 7 released, we saw very little use of the HHVM driver for MongoDB. Some months ago I did a twitter poll, where very few people were indicating that they were using HHVM—and even if they were, they would likely not choose to switch to HHVM given the current climate.

He includes some of the responses in his post ranging from people saying that HHVM only "masked slow code" for them. Another mentioned that, while Hack has some nice features, PHP moves on and integrates some of these ideas anyway. As a result of this disinclination towards HHVM on new development and the low adoption of the HHVM MongoDB extension, it will no longer be maintained. If you're a user and are interested in keeping development going, contact Derick for more information.

tagged: hhvm mongodb driver support discontinued

Link: https://derickrethans.nl/mongodb-hhvm.html

Derick Rethans:
Natural Language Sorting with MongoDB 3.4
Dec 16, 2016 @ 15:28:33

Derick Rethans (of MongoDB) has posted an update to his site sharing the details about an improvement that comes with MongoDB 3.4 and is supported by the PHP driver: natural language sorting.

Arranging English words in order is simple—most of the time. You simply arrange them in alphabetical order. Sorting a set of German words, or French words with all of their accents, or Chinese with their different characters is a lot harder than it looks.

[...] Years ago I wrote about collation and MongoDB. There is an old issue in MongoDB's JIRA tracker, SERVER-1920, to implement collation so that sorting and indexing could work depending on the different sorting orders as described for each language (locale). Support for these collations have finally landed in MongoDB 3.4 and in this article we are going to have a look at how they work.

He starts off by explaining a bit about how Unicode collation works and PHP's support through the intl extension in the Collator class. He provides a code example using the class, showing the difference in sorting them first as English words then as Norwegian words. He moves into the MongoDB world and shows how the queries using this new collation support would be structured before moving back to PHP and using the MongoDB client to make the same requests. He also includes examples showing how to set the default locale, the "strength" (for the level of comparison), sorting and some interesting quirks with certain locales.

tagged: mongodb derickrethans natural language sorting tutorial driver

Link: https://derickrethans.nl/mongodb-collation-revised.html

Derick Rethans:
Not Finding the Symbols
Dec 01, 2016 @ 15:58:22

In this new post to his site Derick Rethans about an issue that was discovered with the newer version of the PHP MongoDB driver dealing a JSON encoding/decoding error.

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".

The driver makes use of the JSON extension's "JsonSerializable" interface to handle some of the BSON types (like binary data). They were surprised that, despite running their tests on a wide range of builds they never came up with this same issue, compiling them from source. The key here is that the JSON extension is bundled along with the binary when compiled this way however some linux distributions do things differently. They ship it as a separate module and, because this could potentially be missing, a JSON error like the one reported could occur. He goes on to talk about some specific examples from various distributions and the simple fix - ensure the JSON extension is loaded before the MongoDB driver is loaded in your installation. This prevents the JSON handling from being missing and the JSON-related error message from popping up.

tagged: mongodb driver undefined symbol error message extension troubleshoot

Link: https://derickrethans.nl/undefined-symbol.html

Kevin Schroeder:
Excluding Fields in the MongoDB/MongoDB Library
Mar 31, 2016 @ 16:18:05

In this new post to his site Kevin Schroeder has shared a helpful hint around the MongoDB library and excluding fields from the results of a query.

I am using the mongodb/mongodb library for a project of mine. The API seems fairly different from the old PECL library and it also came with some other, albeit unexpected, baggage. [...] One of the practices I’ve heard about Mongo is to get Mongo to do as much as it can, but not to worry too much about complicated joins and such as you would in SQL. In other words, don’t shy away from bringing data into the application to do some processing. That was the practice I followed, which worked fine up until my data size started to increase.

He started seeing some major performance issues when his data set grew to a significant size (50% of the response time). He went searching for a solution, tried MapReduce but eventually came upon an optional parameter letting him tell the Mongo DB to omit a value (or values) from the result set. Using this he dropped 7.5 seconds off of his wall clock time.

tagged: exclude fields result set mongodb library example parameter

Link: http://www.eschrade.com/page/excluding-fields-in-the-mongodbmongodb-library/

Derick Rethans:
New MongoDB Drivers for PHP and HHVM: Cursor Behaviour
Mar 08, 2016 @ 17:52:14

Derick Rethans has posted the next part of his series looking at the new an improved MongoDB drivers for PHP in this post to his site. This time he focuses on the updates to cursor behavior from the previous versions.

We released a new version of the MongoDB driver for PHP (the mongodb extension) near the end of last year. In a previous blog post, I covered the back story of the how and why we undertook this effort. And in another post, I spoke about the architecture of the new driver. In this episode I will discuss changes in cursor behaviour.

I recently found the following comment added to the driver's documentation, on PHP.net, which read: "I noticed that ->sort is missing from the cursor. Seems like the old driver has more functionality."

The new driver certainly allows for sorting of results of queries, but no longer by calling the sort() method on the cursor object. This is because cursors are now created differently than in the old mongo extension.

He starts by talking about how the legacy driver handled its cursor functionality and when it actually performed the data lookup (hint: not until used). In the newer drivers the cursor request is made when the object is created. Because of this change, actions like "sort" and "skip" have to be sent as options on the query instead.

tagged: mongodb drivers hhvm cursor behavior difference version

Link: https://derickrethans.nl/new-drivers-part3-cursor.html

Derick Rethans:
New MongoDB Drivers for PHP and HHVM: Architecture
Jan 12, 2016 @ 15:37:59

Derick Rethans continues his look at the latest version of the MongoDB drivers for both PHP and HHVM with this look at their architecture and how it's different from previous versions.

We recently released a new version of the MongoDB driver for PHP (the mongodb extension). This release is the result of nearly a year and a half of work to re-engineer and rewrite the original MongoDB driver (mongo). In the previous blog post, I covered the back story of the how and why we undertook this effort. In this new blog post, I will talk about the architecture of the new driver.

He uses the goals stated at the end of his previous post and covers:

  • Support for Other PHP Engines like HHVM
  • [How/Why] The Driver Should Be Bare Bones
  • No Reinvention of the Wheel
  • Provide an Easy to Use API
  • Backwards Compatibility

From there he then gives an overview (complete with a handy graphic) of the overall MongoDB PHP ecosystem and where the extensions fit in the plan.

tagged: mongodb derickrethans drivers hhvm architecture series part2

Link: http://derickrethans.nl/new-drivers-part2.html

Derick Rethans:
New MongoDB Drivers for PHP and HHVM: History
Dec 02, 2015 @ 16:53:33

In this post to his site Derick Rethans talks about some major updates that have been made to the MongoDB drivers for both PHP and HHVM users.

We recently released a new version of the MongoDB driver for PHP. This release is the result of nearly a year and a half work to re-engineer and rewrite the MongoDB driver. In this blog post, I will cover the back story of the how and why we undertook this effort.

He starts back with the original driver (in 2009), the features it offered and how it was structured. He talks about the evolution of the functionality to more of a C PHP extension and when it reached the v1.0.0 milestone. From there he talks about updates made to the JSON handling, features added in 1.3 and some of the larger design issues they ran up against making future development much more difficult. He ends the post with an overview of their goals for this new driver version and a promise for a following post with more details on this structure.

tagged: mongodb driver version hhvm history overview extension

Link: http://derickrethans.nl/new-drivers.html


Trending Topics: