Archive for the ‘PHP’ Category.

Why I Love the PHP Community

I had my first contact with the PHP community in late 2005 or early 2006; I can’t remember exactly when it was. Before that point, I’d spent the better part of my life struggling with being bullied and depressed and to some degree still do. If my peers didn’t show me ostracism, they mostly showed me indifference. I often felt like my life had little meaning and that I had no one I could relate to.

Then I found the #phpc channel on the Freenode IRC network. I had the honor and privilege of meeting too many individuals to list here. They didn’t belittle me with ego, much as I might have put some of them on pedestals and perhaps still do. They didn’t admonish me for my lack of knowledge or experience at the time. They didn’t laugh or insult me when I asked questions and showed desire to learn like one might expect in other communities.

They welcomed me. They befriended me. They supported me in my endeavors to become better, as a professional and as a person. They made me feel liked, accepted, and respected. They made me feel like a part of something greater, a community, a family of friends. If everyone could have this, I believe the world would be a much better place.

That’s why I’m so sad when I see public displays that I think might prevent people within that community from sharing my feelings or discourage them from taking part in it. I know what it’s like to feel excluded, marginalized, demoralized, degraded, and discouraged. I don’t wish that on anyone, least of all people I know and respect within this community. I feel that people shouldn’t be singled out or made to feel inferior or objectified. Gender, gender identity, race, creed, ethnicity, sexual orientation — no one should be made to feel like this based on those attributes.

I’m a very sympathetic and empathetic person. I feel things very deeply. I try to consider carefully who I might hurt when I say or do something. I may not always succeed, but I try anyway. In any situation, I do my best to understand where other people are coming from and what their position is. I don’t do this for its own sake, but because I know what it’s like to be hurt and I don’t want to inflict that on another human being. And I especially don’t want it inflicted on others in my beloved community either. And I’m not the only one.

PHP as a language irks me sometimes. Heck,  a coworker of mine started phpsadness.com and it’s difficult to disagree with him on many of the problems that the language has. They don’t stop me from using it, though. I may have come for the technology 11 years ago, but I stayed for the community. And hopefully now, after reading this post, you understand why.

Speaking at SunshinePHP

Just a quick post to announce that I’m speaking on “Database Testing for Fun and Profit” at the SunshinePHP Conference being held in Miami, Florida on February 8-9. Hope to see you there!

I am speaking at SunshinePHP. February 8th - 9th, 2013 | Miami, Florida

7php Interview

This post is a bit belated, but 7php interviewed me last month about how I got started with PHP, my work on the PHP Master book, the Phergie project, my advice to beginning PHP developers, and other assorted topics. Feel free to give it a look.

WordPress SyntaxHighlighter font size fix

I use WordPress for this web site. To pretty up source code examples in my posts, I use the excellent SyntaxHighlighter Evolved WordPress plugin. The WordPress theme I use, Fluid Blue, does something with its CSS such that it and SyntaxHighlighter appear to conflict. The result is that source code examples processed by the plugin are displayed with a font size that’s too small to read comfortably.

In doing some digging, I learned about the child themes feature of WordPress, which allows you to effectively extend an existing theme. I created a directory under wp-content/themes called fluid-blue-custom. In this directory, I created a styles.css file with these contents:

/*
Theme Name: Fluid Blue (Custom)
Template: fluid-blue
*/

@import url("../fluid-blue/style.css");

body .syntaxhighlighter code, body .syntaxhighlighter .gutter { font-size: 12px !important; }

The Template line of the comment block indicates that this theme is a child theme of the existing Fluid Blue theme that resides in the wp-content/themes/fluid-blue directory. The @import line pulls in the styles.css file from that directory, after which I can apply any CSS overrides I like. The last line is a CSS rule specific enough to override applicable rules from the parent theme in order to increase the font size to something more easily readable.

It appears I’m not the only one who’s encountered this issue, so I hope this post helps someone else.

Setting up EC2 for Drupal with Puppet

I’m currently working on a project that involves running Drupal on Amazon EC2. To save time in setting up future new VM instances, I decided to take the opportunity to learn puppet. For the time being, I’m using a single VM to run the full LAMP stack and running puppet without a server by copying my puppet manifest to the VM and using puppet’s apply command to apply it locally. However, this manifest can easily be adapted for a multi-VM environment. After some tinkering, I came up with the code below.

class web {
    package { 'httpd':
        ensure => 'present',
    }

    package { 'php':
        ensure => 'present',
    }

    # Update this to use your respective time zone value
    exec { 'php_config':
        command => '/bin/sed -i "s/^;date.timezone =/date.timezone = \'America\/Chicago\'/g" /etc/php.ini',
        require => Package['php'],
    }

    service { 'httpd':
        ensure => 'running',
        enable => true,
        hasrestart => true,
        hasstatus => true,
        subscribe => Package['httpd', 'php'],
    }

    # Drupal requirements
    package { ['php-pdo', 'php-mysql', 'php-xml', 'php-gd', 'php-mbstring']:
        ensure => 'present',
        require => Package['php'],
    }
}

class mysql {
    package { 'mysql-server':
        ensure => 'present',
    }

    service { 'mysqld':
        ensure => 'running',
        enable => true,
        hasrestart => true,
        hasstatus => true,
        subscribe => Package['mysql-server'],
    }

    # Equivalent to /usr/bin/mysql_secure_installation without providing or setting a password
    exec { 'mysql_secure_installation':
        command => '/usr/bin/mysql -uroot -e "DELETE FROM mysql.user WHERE User=\'\'; DELETE FROM mysql.user WHERE User=\'root\' AND Host NOT IN (\'localhost\', \'127.0.0.1\', \'::1\'); DROP DATABASE IF EXISTS test; FLUSH PRIVILEGES;" mysql',
        require => Service['mysqld'],
    }
}

class {'web': }
class {'mysql': }

With this code saved to a file called manifest.pp (.pp being the file extension for puppet manifests), I can spin up a VM and do the following to set it up:

scp -i key.pem manifest.pp ec2-user@host:~/
ssh -i key.pem ec2-user@host
sudo yum upgrade -y
sudo yum install -y puppet
sudo puppet apply manifest.pp
rm -f manifest.pp
exit

At this point, I have a basic Apache/MySQL/PHP configuration capable of receiving a Drupal 7 installation.

Top 10 Posts of 2011

Following in the trail blazed by the likes of Cal Evans and Chris Cornutt, I decided to post a list of the posts on this blog that have received the most traffic this year along with some related commentary. However, in the spirit of Charles St. Michael, I decided to up the number of posts from three to 10. So, here we go:

10. Building PHP-GTK with Cairo Support on Ubuntu Jaunty – 2009-04-25

Very interesting that this post was in the running at all. It’s over two years old, goes back five Ubuntu versions, and deals with PHP 5.3.0RC1 (current is 5.4.0RC4) and PHP-GTK when Cairo support was relatively new. (There’s now a separate PECL extension for it now.) If you want to learn more about this, you should definitely check out Elizabeth Smith and Michael Maclean.

9. Renaming a DOMNode in PHP – 2010-02-09

It seems this isn’t as uncommon a problem as I would have thought. Sadly, in the 22 months that have passed since I authored the post, it seems the DOM extension hasn’t been updated further to support the DOM 3.0 standard or the renameNode() method mentioned in this post.

8. PHP_CodeSniffer Article in php|architect – 2011-04-28

It’s nice to see this post get attention even if was just a brief hand-waving to point people to the article, which is one of two I wrote for php|architect Magazine this year. It’s also nice to see that despite being seen by some as a more menial facet of quality assurance, other people consider it important enough to read the article and take something away from it.

7. ‘New SPL Features in PHP 5.3′ Hits php|architect – 2011-02-01

Another post that was just hand-waving to an article that dealt with a topic I saw as underrated. The article followed my php|tek 2010 session and preceded a Zend webinar this year on the same topic.

6. Process Isolation in PHPUnit – 2010-08-19

Between views and comments, it seems I wasn’t the only one who ran into this head-scratcher. However, if memory serves, I think there are plans to remove this feature from PHPUnit in future versions.

5. Node.js: A Beginner’s Perspective – 2010-10-19

The post is about a year old now, and sadly I haven’t done anything of merit with Node.js since (though I hope to change that), but it seems the community is still as vibrant and growing as it ever was. Heck, you can even integrate PHP-FPM with Node via FCGI now. Node is definitely a technology to continue keeping your eye on if you don’t already use it.

4. PHPUnit and Xdebug on Ubuntu Karmic – 2010-01-03

It’s surprising that this post is still relevant since there have been four Ubuntu releases since the version that this post deals with. I’ve since moved over to Fedora 16, at least for now, and it seems to address most of my regular needs. I may look at other distributions like Mint later on.

3. Models in Zend Framework – 2010-03-26

Even though it’s over a year old now, I think this post gets the traffic it does because there’s not really one prescribed way to build models and because the existing documentation describes a number of components that can be used to build models, but doesn’t really offer specific guidance on how to approach it. Bit of a double-edged sword, I suppose.

2. New SPL Features in PHP 5.3 – 2010-05-20

I published this post on the same day that I gave my session on the topic at php|tek 2010. It’s one of my longer and more content-rich posts and I’ve updated it on occasion as I’ve had cause to update the benchmarks that go along with it. Good to see that interest in SPL seems to be rising.

1. Database Testing with PHPUnit and MySQL – 2010-01-04

While I love that this post is driving as much traffic to my blog as it is, I do want to get around to contributing related documentation to the PHPUnit project. Hopefully that will happen soon. In the meantime, you can also read more about this topic in the Testing chapter of my most recent book.

So, one big take-away from this post has been that most of my high-traffic posts were written last year rather than this year. I can’t say it’s very surprising since, looking back, a number of my posts from this year were of the hand-waving variety. I’m hoping to publish more content-rich posts more frequently in 2012. I won’t call it a resolution, because I’d likely be jinxing myself in the process, but I will say that I’ll make my best attempt.

Best wishes to everyone in the new year.

Appearance on the Engine Yard Podcast

The wonderful folks at Engine Yard invited me and my friends and fellow co-authors Lorna Jane Mitchell and Davey Shafik to be guests on an episode of their PHP podcast with our good mutual friend Elizabeth Naramore as our host.

We discuss our recently published book PHP Master: Write Cutting Edge Code, how SitePoint brought us together to work on the project, what it was like to write the book, and some reflections on the experience from each of us.

If you’ve heard about the book and not read it or been curious as it, I heartily recommend giving it a listen.

PHP Master Published by SitePoint

I’m very happy to announce that I’ve had a second book published: “PHP Master: Writing Cutting-Edge Code.” This time, I had the honor and pleasure of co-authoring the content with my good friends and peers in the PHP community Lorna Jane Mitchell and Davey Shafik and working with the excellent team at SitePoint to make it available to you. The book covers a number of fundamental skills for professional PHP developers including web services, design patterns, security, testing, and more. If you’re in the market for such a PHP title, I encourage you to consider checking it out.

New Articles on PHPmaster.com

I recently started writing articles for PHPmaster.com, a site managed by SitePoint that syndicates PHP tutorials, opinions, and news. You can check out these articles, “Documentation Makes the World Go Round” and “Integrating Amazon S3 using PEAR”, at either phpmaster.com or sitepoint.com. If you prefer getting your news via Twitter, check out @phpmasterdotcom or @sitepointdotcom. Hope you find the articles useful.

ledger stats

Occasionally, I need to take a break from the projects I’m working on. How do I do that? By working on another project, of course!

Just over a year ago, I found ledger and began using it to manage my household finances. Some people may find that sort of thing boring, but I think it’s it neat to look at the past year’s worth of transactions, get a bird’s eye view of our spending, identify trends, and so forth.

I’ve had it in the back of my mind lately that I’d like a better and preferably more visual way to do those things. After perusing through a few charting libraries, I found that Highcharts seem to do what I needed. Among other things, it provides a plugin for the the JavaScript library I’m most familiar with: jQuery.

I already had a bit of PHP code lying around to parse ledger’s XML output, give me a monthly spending breakdown by account, and output it in CSV format. I lifted the parsing logic, wrote some more PHP to search transactions by several criteria based on form input, implemented a very simple plugin system to consume the search results and output various charts, and wrote a few simple plugins. Thus, ledger stats was born.

It’s still in a very rough prototypical stage, but it’s got enough functionality for others to start playing around with it. Feel free to fork it on GitHub and suggest improvements.