Cal EvansInterview with Ross Tuck (21.10.2014, 05:00 UTC)

Twitter: @rosstuck

Show Notes

Brandon SavageIn Defense Of Self-Publishing (20.10.2014, 16:57 UTC)
Back in 2009, I signed a contract to write a book. The book was published by php|architect, and was called The PHP Playbook. It was published in 2011. Being my first book, I assumed that going the route of a traditional publisher made sense, but after publishing a book this way, I opted for self-publishing […]
SitePoint PHPDrupal 8 Hooks and the Symfony Event Dispatcher (20.10.2014, 16:00 UTC)

With the incorporation of many Symfony components into Drupal in its 8th version, we are seeing a shift away from many Drupalisms towards more modern PHP architectural decisions. For example, the both loved and hated hook system is getting slowly replaced. Plugins and annotations are taking away much of the need for info hooks and the Symfony Event Dispatcher component is replacing some of the invoked hooks. Although they remain strong in Drupal 8, it’s very possible that with Drupal 9 (or maybe 10) hooks will be completely removed.

In this article we are going to primarily look at how the Symfony Event Dispatcher component works in Drupal. Additionally, we will see also how to invoke and then implement a hook in Drupal 8 to achieve similar goals as with the former.

To follow along or to get quickly started, you can find all the code we work with here in this repository. You can just install the module and you are good to go. The version of Drupal 8 used is the first BETA release so it’s preferable to use that one to ensure compatibility. Alpha 15 should also work just fine. Let’s dive in.

What is the Event Dispatcher component?

A very good definition of the Event Dispatcher component can be found on the Symfony website:

The EventDispatcher component provides tools that allow your application components to communicate with each other by dispatching events and listening to them.

I recommend reading up on that documentation to better understand the principles behind the event dispatcher. You will get a good introduction to how it works in Symfony so we will not cover that here. Rather, we will see an example of how you can use it in Drupal 8.

Continue reading %Drupal 8 Hooks and the Symfony Event Dispatcher%

Anthony FerraraEducate, Don't Mediate (20.10.2014, 16:00 UTC)
Recently, there has been a spout of attention about how to deal with eval(base64_decode("blah")); style attacks. A number of posts about "The Dreaded eval(base64_decode()) - And how to protect your site and visitors" have appeared lately. They have been suggesting how to mitigate the attacks. This is downright bad.
Read more »
Michelangelo van DamFrom idea to production instantly (20.10.2014, 11:30 UTC)
I know you had it often: you had this crazy idea and worked out a quick prototype and want to share it with the world. So you start up your personal VMS or a VM in the cloud, push your code there and you're happy, all is working.

But this prototype, just like all the other prototypes, grows into a heavily used and very important tool and before you know it you're pushing updates a couple of times a day to production. This still sounds familiar?

And when you're really facing an important update of your code base, all of a sudden you need to spend additional attention to things like heartbleed, shellshock or any other important security exploit that requires immediate updates of all your servers and systems.

Coming from a systems engineering role in the early days of the millennium this shouldn't be a problem for me, but I've got such a passion for development I don't care anymore about everything underneath my code. As long as things are running my way, I rather opt for a full platform as a service (PaaS) than for an infrastructure as a service (IaaS).

What do I use? Microsoft Azure. Yes, I run most of my PHP on Windows, who would have thought that! The reason is simple. If I have my code on GitHub it takes me 5 minutes to create a new instance, hook up my GitHub account and have my application up-and-running in a cloud environment where I don't need to worry about the security of everything below my application. As long I've ensured my application is secured, I know I'm safe. Microsoft Azure will take care of all security below my application.

And I love continuous delivery, so I hook up my Jenkins-CI to my GitHub repo, run my tests and other build steps before the code is merged into a release branch, the branch I hooked up to my Microsoft Azure account so the moment all build steps pass successfully, the code is pushed to production in one, swift transaction.

I love being a developer and I hate spending time patching and updating the platforms that I need to support my applications. Microsoft Azure offers me an easy, affordable and stress-free environment to deploy and maintain my applications in a continuous way. Sign up for the free trial and try it yourself if you don't believe me.
Come and see me at ZendCon where I will be talking about "the continuous PHP pipeline" where I go deeper into the whole flow from idea to production and beyond. And if needed, I will be able to do a live demo getting a scalable solution instantly without the hassle of maintenance. Yes, I love releasing code 5 minutes before I leave on a holiday. And I love you to experience it too.

SitePoint PHPBook Review: Practical Design Patterns in PHP (18.10.2014, 16:00 UTC)

This review of Brandon Savage’s Practical Design Patterns in PHP will include my own opinions and impressions about both the book, and the aspect of self-publishing.

Design patterns are about common solutions to common problems.
… they are concepts, not blueprints; ideas, not finished designs.
… they add clarity to an otherwise difficult situation.
- Brandon Savage, Practical Design Patterns in PHP


Starting out on a lighter, introductory note, Brandon explains the need for frameworks, argues that OOP doesn’t mean just wrapping stuff in classes, and goes into detail on why design patterns appear to be difficult to learn. He then continues with a mild introduction into SOLID principles, and lays the groundwork for more advanced concepts. He explains why each SOLID rule is important and what it means. Given that SOLID is a well established software design principle, it’s only natural to compare it against every pattern that’s about to be explained in the book. Or, to be more precise, to assess how well each pattern respects the SOLID principles, while providing the developer with its intended functionality.

If I express matters in Dreyfus model terminology, he claims the book is there to turn a novice into a competent level developer without subjecting them to advanced beginner mistakes when, in fact, such an approach to learning is not entirely possible - that’s just not how the human knowledge acquisition process works.

Continue reading %Book Review: Practical Design Patterns in PHP%

SitePoint PHPPHP and RabbitMQ: Advanced Examples (17.10.2014, 16:00 UTC)

In part 1 we covered the theory and a simple use case of the AMQP protocol in PHP with RabbitMQ as the broker. Now, let’s dive into some more advanced examples.

Example 1: send request to process data asynchronously among several workers

In the example of the previous part, we had one producer, one consumer. If the consumer died, messages would continue to stack up in the queue until the consumer started again. It would then process all the messages, one by one.

This can be less than ideal in a concurrent user environment with a fair amount of requests per minute. Fortunately, scaling the consumers is super easy, but let’s implement another example.

enter image description here

Let’s say we have an invoice generation service, where the users just need to provide the invoice number, and the system will automatically generate a pdf file and email it to the user. Generating and sending the email could take even several seconds if the server on which the generation process runs is resource limited. Now suppose we are required to support several transactions per second, how do we accomplish this without overwhelming the server?

We need to implement the following pattern:

enter image description here

Let’s look at our producer class:

namespace Acme\AmqpWrapper;

use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;

class WorkerSender
    /* ... SOME OTHER CODE HERE ... */

     * Sends an invoice generation task to the workers
     * @param int $invoiceNum
    public function execute($invoiceNum)
        $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
        $channel = $connection->channel();

            'invoice_queue',    #queue - Queue names may be up to 255 bytes of UTF-8 characters
            false,              #passive - can use this to check whether an exchange exists without modifying the server state
            true,               #durable, make sure that RabbitMQ will never lose our queue if a crash occurs - the queue will survive a broker restart
            false,              #exclusive - used by only one connection and the queue will be deleted when that connection closes

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

Anthony FerraraA Followup To An Open Letter To PHP-FIG (17.10.2014, 11:00 UTC)
A few days ago, I wrote An Open Letter to PHP-FIG. Largely the feedback on it was positive, but not all. So I feel like I do have a few more things to say.

What follows is a collection of followups to specific points of contention raised about my post. I'm going to ignore the politics and any non-technical discussion here.

Read more »
thePHP.ccJoomla PHPUnit Code Sprint (17.10.2014, 07:00 UTC)
SitePoint PHPHow to use RabbitMQ with PHP (16.10.2014, 16:00 UTC)

AMQP (Advanced Message Queueing Protocol) is a network protocol that can deliver messages from one application endpoint to another application endpoint. It does not matter the platform or language of said applications, as long as they support AMQP.

Essentially, one of the application endpoints sends a message, thus being a Producer, through an AMQP broker. In turn the broker will deliver the message to another application endpoint, called the Consumer.

RabbitMQ is an AMQP broker that has support for several programming languages, such as PHP.

The advantage of having a message broker such as RabbitMQ, and AMQP being a network protocol, is that the producer, the broker, and the consumer can live on different physical/virtual servers on different geographic locations.

Also, since networks are unreliable, and applications might fail to process a message completely, AMQP supports message acknowledgements, either automatically or when an application endpoint decides to send them.

RabbitMQ implements the AMQP 0-9-1 protocol. At a glance, it follows the following model.

Hello world example routing


Concept Definition Icon
Producer Application endpoint that sends messages Producer icon
Consumer Application endpoint that receives messages Consumer icon
Connection Handles protocol, errors, authentication, etc… The connection is done using TCP protocol. -
Channel Connections are multiplexed through channels. Even though all channels share the same tcp connection, communication from one channel is completely independent of another. -
Exchange Receives messages from producers and pushes them to queues. Depending on the situation, this can be transparent to the developer. Exchange representation
Queue Buffer that stores messages Queue icon
Message Piece of arbitrary information conforming to the AMQP format that is sent from the producer to a consumer through the broker. The broker cannot modify the information inside the message. -
Acknowledgements Notice sent back from the consumer to tell the server that a message has been received and processed, so the server can delete it from the queue. -

Another advantage of AMQP 0-9-1 is that the application defines the routing logic instead of a broker administrator. This gives the developer a lot of flexibility, without the need to learn a new programming/scripting/markup language.

You can learn more about AMQP and RabbitMQ at the “AMQP 0-9-1 Model Explained” guide. Although not necessary for this tutorial, I encourage you to read it completely.

Continue reading %How to use RabbitMQ with PHP%

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