Derick RethansNew MongoDB Drivers for PHP and HHVM: History (1.12.2015, 09:07 UTC)

New MongoDB Drivers for PHP and HHVM: History

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.

The original driver was created by Kristina and released in early 2009. The extension had a very simple architecture and was written mostly in PHP. A handful of core functions were implemented in C, such as creating a resource for the connection, standard CRUD operations, query execution, and iterating over a result set (sans an Iterator interface). All of the convenient user facing APIs were implemented in PHP code. There were also a few classes to encapsulate certain MongoDB data types that PHP otherwise could not represent, such as its ISODate, ObjectID and Regex types.

A small example to create a connection, insert a document, and retrieve a result set looked like:

<?php include "Mongo.php";

$m = new Mongo();
$c = $m-?>selectCollection("phpt", "find");

$c->insert( array(
        "foo" => "bar",
        "a" => "b",
        "b" => "c")

$cursor = $c->find(array("foo"=>"bar"), array("a"=>1,"b"=>1));

while ($cursor->hasNext()) {

Support for PHP 5.3 was soon added. In this release, much of the syntactic sugar in the form of PHP classes and code had been replaced by implementations in C. Where most (if not all) PHP extensions use phpt tests, the MongoDB driver instead implemented its test suite with PHPUnit tests. The main difference between test methods, is that phpt tests are all run in a separate PHP process in isolation, whereas PHPUnit tests re-use the same process by default. Which means that if one test case causes a crash in the driver, none of the others run either, and no result is visible.

In late 2009, the MongoDB driver for PHP reached a stable state with version 1.0.0. It added a feature to placate some PHP developers that refused to use single quotes around query operators. Query operators in MongoDB have the form of $ + operation, such as $gte for Greater Than or Equal or $set for setting fields during updates. As they are array keys, extra care needs to be taken. For example, the following does not do what you expect it to do:

$r = $c->find( array( "fieldname" => array( "$gte" => 42 ) ) );

The $gte in the double quotes of course causes a variable substitution, usually evaluating to an empty string. Instead of educating users to use single quotes (as in '$gte'), the driver acquired a way to replace the $ symbol to signal a query operator with a different symbol:

ini_set('mongo.cmd', '@');
$r = $c->find( array( "fieldname" => array( "@gte" => 42 ) ) );

The driver would replace these symbols before sending them on to the server. A little later, a warning was added in case an empty array key was found.

The 1.0.0 release also settled issues with serialising PHP variables to database types. MongoDB uses Binary JSON (BSON) as its internal format, and the PHP driver needs to serialize to and from this data type. BSON also supports compound data types, arrays (packed numerical keys), and documents (basically hash maps, or something akin to JSON objects). Because in PHP there is really only one array type, the decision was taken that both BSON documents and BSON arrays would be deserialized into PHP variables as arrays. The following example illustrates this:

<?php // Make a connection, select the 'test' collection in the 'demo' database,
// and clean out the collection.
$m = new Mongo;
$c = $m-?>selectCollection( 'demo', 'test' );

// Construct two documents
// 1. A stdClass object
$docObj = new stdClass;
$docObj->foo = 'bar';

// 2. An array
$docArr = [ 'foo' => 'baz' ];

// Insert documents into the collection:
$c->insert( $docObj );
$c->insert( $docArr );

// Query and show results
$r = $c->find();

foreach ( $r as $record )
        print_r( $record );

The result of this scr

Truncated by Planet PHP, read more at the original (another 4641 bytes)

Cal Evans (Voices of the ElePHPant) Its the Booze Talking – Contributing to Open Source (1.12.2015, 05:00 UTC)

@TessaMero – Tessa Mero

@elstamey – Emily Stamey

@AmbassadorAwsum – Amanda Folson

@ircmaxell – Anthony Ferrar

@Crell – Larry Garfield

@JoePFerguson – Joe Ferguson

Show Notes

The post Its the Booze Talking – Contributing to Open Source appeared first on Voices of the ElePHPant.

PHP ClassesPHP Automated SMS Gateway for Request and Response Service Part 2: Automatic Responses (1.12.2015, 03:00 UTC)
By Dave Smith
Once you start improving your SMS response service using the DOTGO system, the types of the messages that you want to handle get more complex, so you need a better way to organize and process those messages.

Read this article to learn how to how to use the PHP DOTGo Engine package to handle more complex responses using DOTGO Web service's terminating nodes.
Fabien PotencierAnnouncing 24 Days of Blackfire (30.11.2015, 23:00 UTC)

I still remember the excitement I had 15 years ago when I discovered my first programming advent calendar; it was one about Perl. It was awesome, and every year, I was waiting for another series of blog posts about great Perl modules. When I open-sourced symfony1, I knew that writing an advent calendar would help adoption; Askeet was indeed a great success and the first advent calendar I was heavily involved with. I wrote another one, Jobeet, for symfony 1.4 some years later.

And today, I'm very happy to announce my third advent calendar, this one is about Blackfire. This time, the goal is different though: in this series, I won't write an application, but instead, I'm going to look at some development best practices which includes topics like profiling, performance, testing, continuous integration, and my vision on performance optimization best practices.

I won't reveal more about the content of the 24 days as the point is for you to discover a new chapter day after day, but I can already tell you that I have some great presents for you... just one small clue: it's about Open-Sourcing something. I'm going to stop this blog post now before I tell you too much!

Enjoy the first installment for now as it has just been published.

SitePoint PHPFilling out PDF Forms with PDFtk and PHP (30.11.2015, 17:00 UTC)

PDF files are one of the most common ways of sharing documents online. Whether we need to pass our clients’ documents to third-party service providers like banks or insurance companies, or just to send a CV to an employer, using a PDF document is frequently the first option.

PDF files can transfer plain/formatted text, images, hyperlinks, and even fillable forms. In this tutorial, we’re going to see how we can fill out PDF forms using PHP and a great PDF manipulation tool called PDFtk Server.

To keep things simple enough, we’ll refer to PDFtk Server as PDFtk throughout the rest of the article.

Digital document illustration


We’ll use Homestead Improved for our development environment, as usual.

Once the VM is booted up, and we’ve managed to ssh into the system with vagrant ssh, we can start installing PDFtk using apt-get:

sudo apt-get install pdftk

To check if it works, we can run the following command:

pdftk --version

The output should be similar to:

Copyright (c) 2003-13 Steward and Lee, LLC - Please This is free software; see the source code for copying conditions. There is NO warranty, not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

How It Works

PDFtk provides a wide variety of features for manipulating PDF documents, from merging and splitting pages to filling out PDF forms, or even applying watermarks. This article focuses on using PDFtk to fill out a standard PDF form using PHP.

PDFtk uses FDF files for manipulating PDF forms, but what is an FDF file?

FDF or Form Data File is a plain-text file, which can store form data in a much simpler structure than PDF files.

Simply put, we need to generate an FDF file from user submitted data, and merge it with the original PDF file using PDFtk’s commands.

What Is Inside an FDF File

The structure of an FDF file is composed of three parts: the header, the content and the footer:

Continue reading %Filling out PDF Forms with PDFtk and PHP%

Paul M. Jones50% Off “Modernizing Legacy Applications in PHP” (30.11.2015, 14:37 UTC)

For Black Friday/Cyber Monday, and the rest of this week, my books Modernizing Legacy Applications in PHP and Solving the N+1 Problem in PHP are 50% off. If you’ve been waiting for a sale to get these books, now is your chance!

Thijs FerynFabrizio Branca – Talking about Magento & living in the Bay Area (30.11.2015, 08:59 UTC)

This is the last episode of the Zendcon 2015 series. And the term “last but not least” definitely applies here. I

The post Fabrizio Branca – Talking about Magento & living in the Bay Area appeared first on Thijs Feryn's blog.

PHP ClassesHow to Use Queue To Speedup PHP Processing Tasks Part 1: Queueing Slow Tasks (30.11.2015, 05:03 UTC)
By Alexander Skakunov
Queues are an important solution, especially when need to create a processing task that may take a long time to complete and the user or the creating process cannot wait until the task is finished.

This is the case for instance of sending newsletter email messages to many users.

Read this article to learn how queues work and how you can implement one in PHP using a simple database.
Ben RamseyYak Shaving Is the Entire Job Description (30.11.2015, 00:00 UTC)

Earlier this year, I worked on a solution to help us manage changes and history when maintaining different versions of Amazon Machine Images (AMIs). I entertained a wide range of ideas from Docker to AWS CloudFormation to a collection of shell scripts.

Finally, after asking in #pynash (Nashville’s Python user group) on Freenode IRC, Jason Myers pointed me to Packer as a potential solution.

Packer is a tool for creating machine and container images for multiple platforms from a single source configuration.

Packer turned out to be the right tool for the job, but I almost scrapped it, since I ran into a few problems.

When I began my journey as a programmer, every task was fraught with problems, and I loved it. Everything was new, and every problem was an opportunity to learn and grow. It was great.

Somewhere along the way, though, problems became nuisances. As I grew older in life and my career, my tolerance for problems became lower, and my desire for things to Just Work™ became greater.

As I struggled to find a solution for the problem I had with Packer, Tate Eskew reminded me that yak shaving is a part of my job.

<teskew> i'd just patch it, then. keep it in a central place so you only compile it once.
then when it's put into mainline, just switch out the binary
<teskew> either way, it's a pretty simple patch to test and change
<ramsey> ugh… gotta set up an environment just to build packer
<ramsey> "simple"
<teskew> you act like yak-shaving isn't the name of the game
<ramsey> :P
<teskew> hell, it's the entire job description
<teskew> :)
<ramsey> I am not an ops person
<teskew> you are right now :)

I ended up patching Packer for my needs, and I had fun doing it. I learned a valuable lesson that day: Despite how we may gripe and complain about shaving yaks, it’s part of our job as programmers and problem solvers, and often, it’s the part that brings us the most satisfaction. I’ve learned to embrace yak shaving, and doing so has changed my outlook on my job, open source contributions, and community organizing.

Yak shaving isn’t just part of our jobs, it’s the entire job description.

is a web craftsman, author, and speaker. He is a software architect at ShootProof, where he builds a platform for professional photographers. He enjoys organizing user groups and contributing to open source software. Ben blogs at and is @ramsey on Twitter.

“Yak Shaving Is the Entire Job Description” was originally published at and is Copyright © 2015 Ben Ramsey. It is licensed for use under a Creative Commons Attribution-ShareAlike license.

Liip PHP 7.0.0 (RC8) for OS X and CloudFoundry (28.11.2015, 08:38 UTC)

PHP 7.0 is very very near, if no showstoppers show up during the current Release Candidate #8. And I finally managed to update the package on, so that you can test and start writing applications on your local OS X machine easily, as well. The installer also automatically does the right thing in the apache configuration with regards to “mod_php7” and “mod_php5”.

Furthermore, since we are using CloudFoundry in one of our bigger projects, I also extended the official PHP buildpack to include PHP 7.0 (and some other things like varnish, but that’s not relevant for this). This way we can easily see, if our apps still work with PHP 7 and do some benchmarks (the initial ones looked promising). To use the buildpack, add the following line to your manifest.yml


and adjust .bp-config/options.json to include (and maybe also change your composer.json to use PHP 7)


Be aware, that I didn’t port many of the extensions the official buildpack includes, so your milage may vary. And if you want to be sure it’s thoroughly tested, maybe better wait for official PHP 7.0 support in the CloudFoundry buildpack. I’m sure, they won’t wait long once it’s is released.

There’s now no excuse anymore to not test your apps against PHP 7.0

LinksRSS 0.92   RDF 1.
Atom Feed   100% Popoon
PHP5 powered   PEAR
ButtonsPlanet PHP   Planet PHP
Planet PHP