php

29 May

Using Fabric to Create a LAMP server on HP Cloud

in cloud, hpcloud, lamp, php, programming, python

FabricFabric
Fabric is a network-aware build tool. Think of it like make (or rake, or pake, etc.) for remote servers. With Fabric, it is just as easy to script a remote environment as it is to script a local one. In fact, with Fabric, you can do both.

Fabric can actually be used to automate installing a server in the cloud. In this article, I show how to use Fabric with the hpcloud UNIX client to create an HP Cloud server instance and then configure it as a LAMP server.

While I show this with HP Cloud, the technique could readily be adapted to other cloud providers like OpenStack or AWS.

Updated: Fixed indenting that was breaking Python. Thanks to aeronotix.

26 Apr

XHProf in 30 Seconds: How to get started profiling PHP

in performance, php, programming, xhprof

The task was simple: I wanted to run xhprof (the Facebook-developed PHP profiler) to get some quick-and-dirty metrics on a PHP script. While xhprof is actually really easy to install and use, I had to read a surprising amount of material in order to run a simple install and write three lines of code.

To spare others the agony of cruising old Facebook docs in the Internet Archive, here's a 30 second guide to installing and using xhprof.

25 Apr

Misplaced Optimization: A story of PHP performance woes

in drupal, performance, php, programming

I recently began working on some PHP code for resolving HTML5 entities into their Unicode codepoints. According to the code, it had been optimized for performance. The code was moderately complex, and the authors appeared to have gone through great pains to build a specialized lookup algorithm. But when I took a closer look, I doubted. I decided to compare the "optimized" version with what I would call a naive version -- the simplest solution to the problem.

Here I show the two solutions, and then benchmark them for both memory and speed.

04 Jan

PHP SPLObjectStorage v. Arrays: Redux

in benchmarks, php, programming

A few years ago, I tested SPLObjectStorage and Arrays to see which performed better. My conclusion at the time was that SPLObjectStorage is the better performer.

One thing I did not examine there was the implications of size. I ran tests with a fixed size of 10,000 elements. The test was also run on PHP 5.2.

A recent email from Frederik Krautwald caused me to re-evaluate these benchmarks. Using PHP 5.4.10 on Windows 7, Frederik generated this set of benchmarks:

26 Oct

PHP and curl_multi_exec

in curl, performance, php, programming

This post explain how to get data off of a curl_multi handle. Some time back I posted this snippet of code inside of a larger sample of code:

<?php
  $active = NULL;
  do {
    $ret = curl_multi_exec($multi, $active);
  } while ($ret == CURLM_CALL_MULTI_PERFORM);
 
  while ($active && $ret == CURLM_OK) {
    if (curl_multi_select($multi) != -1) {
      do {
         $mrc = curl_multi_exec($multi, $active);
      } while ($mrc == CURLM_CALL_MULTI_PERFORM);
    }
  }
?>

I didn't really document or explain it. And so it seems that this code snippet has caused some confusion. Let me explain what it does.

07 Sep

How Fortissimo Does Dependency Injection

in fortissimo, php, programming

Dependency Injection (DI) is a software design strategy for making software more flexible by passing an object the components it needs to get its job done. This is more flexible than having each object manage its own components. If you are not familiar with DI, check out a great introduction.

Fortissimo comes with Dependency Injection built-in. Not only is it built in, but it's transparent. You don't need to learn anything about dependency injection containers or inversion of control.

In this post, we'll look at the most common dependency injection mechanism in Fortissimo.

01 Sep

VOTE: A potentially major change to QueryPath.

in drupal, php, programming, querypath

TL;DR: There's an experimental version of QueryPath 3 for you to try and let me know what you think: https://github.com/technosophos/querypath/zipball/3.0.0-experimental-fin...

Either respond at support-querypath@googlegroups.com or to @querypath on Twitter.

Read on for the onger explanation.

07 Aug

Biography of the PHP HPCloud Library

in drupal, php, programming

The first two articles in a series about the HP Cloud PHP bindings is available on the Cloud Matters, the official HP Cloud blog. Matt Farina is writing this series.

The HP Cloud library, which is developed on Github, is a project Matt and I started. It wasn't intended to be part of HP's offerings. Instead, we started the project because we wanted to build our own tools to work with our cloud services. We have a number of specialized internal tools that we use for things like debugging the Identity Service catalog or taking snapshots of DBaaS instances.

We also wanted to be able to store Drupal assets inside of Object Storage, and building a PHP library was the first step. (The second, of course, was to build an HP Cloud Drupal module).

The high point so far has been launching our new blog entirely inside of our own cloud architecture, powered in a large part by this PHP code. We'd been dipping our toes in the water, but this was a head-first plunge.

It's been rewarding to see this library go from "scratching our own itch" to being generally useful for others. The library still has a way to go, and we've just about pushed it to 1.0, but I'm encouraged to see how far it has gone already.

30 Jul

HP Cloud Runs Drupal In Our Own Cloud

in drupal, hpcloud, php, programming, stackato

HP Cloud has migrated its blog site into Drupal. This makes the fourth Drupal migration for HP Cloud. But it is the first one to be running entirely inside of our own cloud.

We're using HP Cloud Compute instances, our Relational Database in-cloud MySQL server, Object Storage for all static files, and CDN to seamlessly serve public files out of a content distribution network. What is more, we now have a Stackato-based architecture for rapidly deploying Drupal sites into the cloud.

Over on the HP Cloud blog, I've got an article explaining the architecture.

16 Jul

Buy a Book for Aaron Winborn

in drupal, php

Aaron Winborn is a prolific contributor to Drupal, not just code-wise but as a community member as well. He's been diagnosed with Amyotrophic Lateral Sclerosis (ALS), a degenerative nervous disease that will shorten his lifespan considerably. He has posted about his condition and its impact on his family on his blog.

Along with the the other co-authors of Drupal 7 Module Development, I am donating my portion of the 3rd and 4th quarter royalties of this book to a special needs trust for the Winborn family.

Drupal 7 Module Development is a great book for those interested in getting started with Drupal development. If your looking for a good Drupal book, please consider buying this one. 100% of the royalties will go to the Winborns.

Even better, contribute directly to the trust. Our royalties work out to only a few dollars per book. A direct contribution will go a lot farther.