2012年8月31日星期五

Site News: Popular Posts for the Week of 08.31.2012

Popular posts from PHPDeveloper.org for the past week:

Justin Carmony: Refactoring or Rebuilding: Working with Legacy Code


In this post to his site, Justin Carmony shares some of his experience in working with a legacy code base and shares some of the steps he's taking in his own work to modernize it.



There is [still] one big piece written in a less than ideal system. Its still PHP, but much more hacked together. It is our backend CMS system for controlling the website. It is painful to use, and we get many complaints all the time about it. [...] on Twitter, I saw a link for a talk Paul M. Jones gave at the Nashville PHP Usergroup. It was entitled: "It Was Like That When I Got Here: Steps Toward Modernizing a Legacy Codebase." I couldn't think of a better title for that talk, nor a better talk to listen to at this very moment.


He mentions the steps he taking to further advance his own project towards a better, non-legacy state including an audit of the current functionality and getting input from users as to which features give them the most pain.



Using these lists to decide what to refactor, we can get the biggest gains for the least amount of work. If we were to rebuild, we would get the smallest gains (if any) of barely having something functional with the greatest effort.

Reddit.com: PHP now, as an outdated developer


In this recent post to Reddit.com, the author recounts some of his past experience in technology and the steps he's taken along the way to improve himself. He's at a loss now, though, and wants recommendations for what to do next (a familiar situation for many):



I started 12 years ago designing websites. back then the fun and the complexity were playing with css, javascript and dhtml. [...] So right now i need some advice because im kind of lost facing so many possibilities. I want to learn the MVC approach, but i think that doing it by learning a different language (like ruby) will help me to increase my knowledge and being able to work with CI, Cake, Zend or Symphony more naturally. What should i focus first? web design tools? frameworks? mobile programming? NoSql databases?


Responses so far talk about things like using version control, even just in personal projects, the usefulness of Ajax/modern Javascript, more advanced CSS techniques, SOA and some framework suggestions to fill the MVC desire.



Do you have a recommendation on what'd be a "next good thing" to learn in the current web development world? Share it here!

Pivory.com: From Ajax to WebSocket with PHP, a Quick Example


On Pivory.com there's a new topic (tutorial) showing you a simple example of using WebSockets with the Ratchet PHP library, complete with sample code.



WebSocket is the modern way for realtime two-way communications between server and browser. In the beginning we have Ajax calls [...] and with WS in picture the logic becomes [different]. [There] is a separate WS server, say listening on xxx.xxx.xxx.xxx:8080, and it can send messages to connected clients in realtime at any moment. The WS server can be in any language (such as node.js + socket.io) and on any machine or even in a cloud service. I use PHP (try http://socketo.me for Ratchet) because I am lazy.


The example shows a basic PHP Web Socket server running on a port with methods for "on connect", "on close", "on error" and "on message send". There's an example of the Javascript code to connect to this socket, showing how to convert it over from Ajax usage.

2012年8月30日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

PHPMaster.com: Patterns for Flexible View Handling, Part 1 - Working with Composites


PHPMaster.com has started up a new series today with the first part of a set of tutorials looking at design patterns that can be used in the handling of your views to make them more effective and easier to maintain.



To overcome your skepticism [of an easy to use, flexible view system], in this two-part tutorial I'll show you how to implement from scratch a couple of customizable view handling modules by sinking our teeth into the goodies of the Composite and Decorator patterns.


He starts off by creating a foundation to work from - a basic View class that takes in data, allows for the setting of a template and combines it all together when "render()" is called. He then takes this example and applies the Composite pattern and creates interfaces for the template, container and view, implements them and shows how to attach views to other views. Each of these views is then rendered when the main "render()" method is called and the output is appended.

Rob Allen: Setting up PHP & MySQL on OS X 10.8 Mountain Lion


Rob Allen has posted some notes to his site helping you get PHP set up on OSX Lion (10.8) successfully.



With OS X 10.8, Apple continues to ship PHP 5.3 with Xdebug, PEAR, GD and PDO_MYSQL. This is how to set it up from a clean install of 10.8.


He's broken it up into a few sections including the MySQL setup, Apache configuration
, updating the main php.ini and setting up PHPUnit ("and friends") for your testing. He also includes setup instructions for the mcrypt and the PECL OAuth extensions.

Miro Svrtan: Debugging Uploadify jQuery plugin with XDebug


Miro Svrtan has a quick tip for those using the Uploadify plugin in their application's file uploads - how to enable XDebug debugging on each upload request.



If you ever decided to use Uploadify jQuery plug-in you might have noticed problems with debugging remote PHP code that this plugin relies on. [...] Unfortunately setting this up will not work with Uploadify Flash version since calls to remote server side is not done inside browser but inside flash plugin. [...] Few months ago I found my self blindly debugging it again and remembered that I read somewhere that xdebug parameters can be sent via GET/POST too.


He takes advantage of this fact and appends the "XDEBUG_SESSION_START" and "XDEBUG_SESSION" values in the "scriptData" handler for the Uploadify call. The XDebug session is then started when the script executes and your IDE will receive the results.

2012年8月29日星期三

Community News: Latest Releases from PHPClasses.org

DZone.com: How to correctly work with PHP serialization


In this new post to DZone.com today Giorgio Sironi takes a look at the serializing functionality in PHP and how it works with both regular variables and objects.



PHP is able to automatically serialize most of its variables to strings - letting you save them into storage like $_SESSION. However, there are some tweaks you have to know to avoid exploding .php scripts and performance problems.


He gives some code snippets showing the serialization of variables and objects and points out a few things that can't be effectively serialized (like resources and closures). The mentions the "__sleep" and "__wakeup" magic methods for automatic class serialization and mentions the Serializable interface that comes built in to PHP.

DevShed Forums: PHP is a fractal of bad design? Hardly.


A while back there was an article that put a negative spin on PHP ("PHP: a fractal of bad design") and there was a huge community response to it with over 1400 comments on the post itself. Over on the DevShed forums, there's a lengthy new post that goes back over that article, piece by piece, and evaluates everything that was said.



As I've seen this article a number of times, I'd like to go through it to see what everyone has to say on the subject. Warning: This is just stupidly, ludicrously long. it takes an existing 5-page article and tears it apart nearly sentence-by-sentence.


He goes back through each of the sections - Stance, Arguments, Philosophy, etc - and includes quotes from the articles and his own impressions/thoughts about them. There's a section covering some of the individual complaints that were mentioned and things like PHP's OOP model and security.

User Group - Lake/Kenosha County Hosts Elizabeth Naramore


On Tuesday, September 11th, the Lake/Kenosha County PHP User Group will be hosting their next meeting - a special presentation from Elizabeth Naramore (a community evangelist from Engine Yard) with her talk "Get a Hammer for that Nail!"



This month we have a special guest - PHP Luminary Liz Naramore! Liz currently works for the premier PHP PaaS provider EngineYard. She's a co-founder of phpWomen & is an active member of OINKPUG (the Ohio, Indiana, and Northern Kentucky PHP User Group). A frequent speaker at tech conferences and online seminars, she's bringing her expertise to Lake / Kenosha PHP Tuesday, September 11th at 7pm.


If you're in the Milwaukee, WI area on the 11th and want to check it out, you can get more details (and RSVP) on their Meetup page. The meeting starts at 7pm at Bucketworks.

Liip Blog: Symfony documentation in French is online!


On the Liip blog Thomas Botton points out that the French translation of the Symfony documentation is no online and available for public consumption! He was a part of the group that worked on the translation.



A year ago, I started to work with the Symfony documentation French translation team. At this time, I was actually not imagining that it would take so long to get all that work done.. In case you don't know, as of today, the Symfony documentation team already wrote more than 300 documents! Counting 1 to 4 hours to translate one doc plus the time to review it, you get an idea of the overall workload! But anyway, it's done: the Symfony documentation French translation is finally live on symfony.com!!!


He also mentions some of his reasoning for being a part of the team including it being a way to get more involved with Symfony (and open source) in general and the benefit it now provides to French-speakers wanting to get into the framework. You can find the documentation here.

2012年8月28日星期二

Community News: Latest PECL Releases for 08.28.2012

Latest PECL Releases:

PHPMaster.com: Artisan and Laravel Migrations


PHPMaster.com has continued their series about the Laravel framework today with this new tutorial they show you how to use the command line tool Artisan to work with database migrations.



For those who struggle with maintaining their database schema, or who have problems applying updates and often revert them, there is a solution. Laravel, the MVC framework which I wrote about previously, offers you migrations.


On the surface, the migrations are simple sets of "up" and "down" methods that allow you to apply and remove the changes required for the migration. It also allows you to perform a "rollback" on the updates just made and a "reset" to clear out all changes and start over from the base. There's also a shortcut to help generate migration code from a configuration string.

Community News: PHPNW 2012 Tutorial Day Sessions


This year's PHPNW conference is bringing back the tutorial day for this year's event, giving you access to hands-on sessions from several well-known people in the PHP community on a wide range of topics.



Have you ever been to a conference talk and wished the speaker could come and spend time with you to really explore the real 'nitty-gritty' of the topic? Well so have we, and that's why following last years success, PHPNW are again offering you this exceptional opportunity in the form of a tutorial day which will kick off the whole conference weekend.


This year's sessions include:




This year's event is happening October 5th, 6th and 7th in Manchester, UK with the Tutorial sessions being the first of the three days. You can find out more about the event (and tutorials) on the main conference site. Ticket sales are also open and Early Bird pricing is in effect until September 4th, so hurry to get in on this great price!

Miro Svrtan: PHP Fatal errors into exceptions natively


Miro Svrtan has a new post today proposing something that could be added to help handle bad method calls in PHP apps - using the BadMethodCallException (pre-existing) instead of throwing fatal errors.



Using getter method that is not implemented will get you fatal error saying how undefined method is called and request will stop. [...] On the other hand if you would use public property all you would get is a notice saying how this property does not exist and rest of request would be completed. [...] I know that this is due to dynamic typing behavior of PHP and no I am not suggesting raising a notice if undefined method gets called but since 5.1.0 there is a BadMethodCallException class which would be perfect for this situation.


There's been other people that have proposed the same idea as a bug, but nothing formal has been submitted as an RFC to make the change. Miro is looking for feedback to find if others would be interested in this feature and want to make the proposal (leave comments here).

Forrabbit.com: BETA survey results


Forrabbit.com has conducted a survey of developers world-wide about what kind of platform, tools and software they use in their development work. They've posted the results to their site today, the answers from about 160 different developers.



We have asked our readers a few questions on their PHP workflows, hosting and tools. We are very curious about this, because we want to build the best PHP PaaS for dev guys.


Some of the highlights from their findings include the large share of Zend Framework use, the predominant use of git for deployment, MySQL still being the database of choice and multi-stage deployment (environments) are a preferred setup. You can see the full results here [pdf].

2012年8月27日星期一

Gonzalo Ayuso: How to use environ variables to create different environments with PHP


Gonzalo Ayuso has a new post to his site showing how you can set up and use environment variables to make different environments for your applications.



If you use a framework such as Symfony2 this problem is solved for you, but if you aren't using any framework you probably need to solve it in one way or another. [...] The solution that I like for this kind of problem [with having different environments] is to use apache's environ variables. We inject the environ variables in the virtual host configuration.


He shows how to add a variable to the VirtualHost section of your Apache config, how to use the getenv function to retrieve its value and how to use it to select a configuration set. This method can also be applied to other kinds of information including settings you may not want to hard-code directly in you app (like possible database credentials).

Matt Frost: Starting with Selenium (and Headless on a VM)


Matt Frost has posted a two part series of some of his experiences in setting up Selenium to execute it in a VM and run tests on your application.



I was a little scared when it came to setting up Selenium, I figured it was going to be difficult to setup and configure. So I was pleasantly surprised when it really wasn't. So here are a few of the mistakes I made; since I use Vagrant to do all my development I actually grabbed Selenium and started from there. Not a good place to start, although as I found out later; not a total dead end.


He includes the initial setup of things like PHPUnit and the Selenium .jar file as well as a sample test that loads a page and checks the title of the page. His second post shows how to set it up in the VM (using Vagrant, xvfb to capture the output and Firefox to execute the tests).

Engine Yard: Chicks That Rip Podcast: Interview with Laura Thompson


On the Engine Yard Developer Center today there's a new episode of their "Chicks that Rip" podcast series - an interview with Laura Thompson, a development manager and member of the PHP community.



Elizabeth Naramore interviews Laura Thomson about being a manager, the current state of PHP and speaking at Hacker School.


They talk some about Laura's background in development and PHP, how she learned to become a manager of a development group at Mozilla, the Hacker School event and some of the things she's seen happening in the PHP community. You can listen to this latest episode by downloading the mp3 or subscribing to their feed.

Pádraic Brady: PHP Security: Default Vulnerabilities, Security Omissions & Framing Programmer


In this new post (and this related article) Pádraic Brady shares some of his opinions about default security languages should provide and the Secure by Design principles.



Odd though it may seem, this principle explains some of PHP's greatest security weaknesses. PHP does not explicitly use Secure By Design as a guiding principle when executing features. I'm sure its in the back of developers' minds just as I'm sure it has influenced many if their design decisions, however there are issues when you consider how PHP has influenced the security practices of PHP programmers. The result of not following Secure By Design is that all applications and libraries written in PHP can inherit a number of security vulnerabilities, hereafter referred to as "By-Default Vulnerabilities".


He focuses on what he sees as a responsibility of those creating the language to either default to a more secure architecture or provide information as to why their choices could cause problems. In the extended version of the post, he talks about some specific issues that the language has including SSL/TLS misconfiguration, openings for XML entity injection attacks and limited native filtering for cross-site scripting.

2012年8月24日星期五

Site News: Popular Posts for the Week of 08.24.2012

Popular posts from PHPDeveloper.org for the past week:

Evan Coury: Q&A about software engineering


In response to some questions he got from a student, Evan Coury has shared the answers to his questions about software development and engineering:



I found his questions to be well-posed and thoughtful, so I figured I'd post my responses as a blog post. I'll be sending this post to Jordan, so if anyone has additional comments or advice for the kid, please feel free to leave some wisdom in the comments!

Some of the questions include:



  • Describe the duties and responsibilities of someone working in software engineering.
  • Do you have assignments that seem to drag on forever, or are they usually pretty quick?
  • Are there any specific tools or equipment required for your job?
  • What are the advantages/disadvantages?
  • So do most people work for themselves, private industry, or the government?


You can read Evan's answers to these and more in the full post.

NetTuts.com: Automatic Testing for TDD with PHP


If you practice the TDD (test-driven development) methodology in your work, you know that sometimes switching back and forth between a terminal and your IDE can be distracting. In this new tutorial from NetTuts.com, they show you how to streamline things a bit with a simple Ruby script.



Traditional test-driven development can, at times, be cumbersome. You have to stop writing code in order to run your tests. Luckily, there are solutions, which provide the ability to automatically run your tests as you code. In this tutorial, you will learn how to use a Ruby gem, called watchr, to monitor your code and automatically run the appropriate tests whenever you save your work.


The IDE doesn't matter in this case because the "watchr" tool keeps an eye on when things change in the watched directory and automatically fires off a script when it sees an update. They include the few short lines of Ruby to make it all happen and even have the "notify-send" command built in to give you a popup about the pass/fail status.

Project: Box - Making Creating PHARs Easier


There's a new project on Github that wants to help making your phar archives for your PHP applications. The process is a little obtuse right now and Box wants to simplify it.



Box is a library and command line application for simplifying the PHAR creation process. [Features include] creating new PHARs with a simple configuration file, add and replace files in existing PHARs, extract existing PHARs, with option to cherry pick files and verify PHAR signatures.


The project is still relatively young but it looks like it's off to a good start. Phar files are a powerful tool to have in a PHP developer's arsenal but developing them can be a pain. Hopefully something like this can make life easier.

2012年8月23日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

Anthony Ferrara: Object Scoping: A Triste Against Service Containers


In his most recent post Anthony Ferrara talks about service containers, the cousin of dependency injection containers (DIC) that he argues aren't much better than global variables.



I am a firm believer that service containers are not a form of Dependency Injection, and are only slightly better than global variables. That led me to make a few comments that elicited a reply from two Fuel developers. That led to a rather interesting debate that just couldn't fit into 140 characters [on Twitter]... So I'm going to go into topics that are tightly related: variable scoping and service locators.


He starts by defining what global variables are (including the requisite Wikipedia definition) and how they're commonly use "everywhere" in the application, both set and read from. He contrasts this idea against a static variable from a class and redefines the scoping a bit when talking about objects and their properties.



So how does this apply to service locators (aka service containers or dependency injection containers)? Well, all state that's managed by a service locator immediately becomes global state to the objects that use the locator. So why is it all the rage? It's simple. It seems simple on the surface. If your object needs another dependency, there's no need to adjust how it's constructed, just pull it from the locator. Sounds great, right? Well, not quite.


He points out some of the main issues with using service locators namely difficulty in unit testing them, dependencies within the container, how it violates both the Law of Demeter and the Single Responsibility Principle as well as causing "hidden coupling" issues.

PHPMaster.com: Installing GitList for Local Repos


If you're a git user and have thought about bringing things a bit more "in-house" than GitHub but still want some of the perks of the web-based interface, this quick tutorial from PHPMaster about installing Gitlist might interest you.



aking your repositories available in a local intranet is pretty easy, but having a nice interface to interact with those repositories, making collaboration between teams easier, is not that simple. [...] There are other solutions available, but some are too hard to install or, again, hard on the eyes. I recently discovered GitList, a free and open source Git repository viewer. It's interface resembles GitHub a lot but aims to keep everything simple and clear.


He includes the basic installation steps you'll need to get it up and running - setting up the environment, downloading and configuring Gitlist to look at your repositories and pointing out that, since the LESS source is included in the download, you can customize it how you see fit.

Community News: PHPBestPractices.org - A Short Practical Guide


There's another site tossing their hat into the "best practices in PHP" ring (the other being PHP The Right Way) with what they call a "short, practical list for common and confusing tasks" in PHP - PHPBestPractices.org.



[Outdated tutorials and information is] one of the reasons why new PHP programmers are so frequently blamed for ugly, outdated, or insecure code. They can't help it if the first Google result was a four year old article teaching a five year old method! This document tries to address that. It's an attempt to compile a set of basic instructions for what can be considered best practices for common and confusing issues and tasks in PHP. If a low-level task has multiple and confusing approaches in PHP, it belongs here.

The site has sections for topics like:




If you're interested in helping out and adding more content to the site, contain the maintainer and let him know.

2012年8月22日星期三

Community News: Latest Releases from PHPClasses.org

Gareth Heyes: PHP nonalpha tutorial


Gareth Heyes has another post to his site on the topic of "non-alpha PHP code", this time getting a bit more into the process and how his examples are parsed by PHP into more familiar functionality.



My first post on PHP non-alpha numeric code was a bit brief, in the excitement of the discovery I failed to detail in depth the process. I've decided to follow up with a tutorial and hopefully explain the process better for anyone wanting to learn or improve the technique. The basis of PHP non-alphanumeric code is to take advantage of the fact that PHP automatically converts Arrays into a string "Array" when using in a string context.


He includes some basic examples showing how, with just a combination of things like "+", "_" and "[" or "]" you can reproduce similar output to echoing out an array and use that "Array" output string to get to other strings (like the letter "B"). There's also a more lengthy example showing how to build up the string "print 1+1" and have it execute using this technique.

Chad Minick: PHP frameworks are obsolete


In his latest post Chad Minick shares some thoughts as to why he thinks PHP frameworks are obsolete and how, despite there still being a use for them, a lot of them are just trying to solve the same problems all over again.



Now before I start getting hate mail, let me explain that I still think there is a market for PHP frameworks. I think if you have a moderately low traffic site that's going to live on shared hosting, and is basically a CRUD application on top of MySQL, disregard this article, it probably isn't for you. However, I've seen so many projects start out with that scope. They either grow or the developer/client wants to add more fancy new features they are starting to see elsewhere on the web. Then I see all these PHP developers hacking things that the PHP stack really isn't meant to do.


He takes some of the core features of several of the popular frameworks out there and breaks them out into a list of technologies that do that work themselves (such as "Web Server", "Dependency Management", "Caching" and "Messaging"). He points to a Java/Scala framework, Play as
an example of having several of these technologies built-in where you don't have to have a whole other set of skills to use them effectively. It's an interesting idea but seems a little NIH to me.

Phil Sturgeon: Understanding Circumstance


Phil Sturgeon has a new post to his site today comparing a few different types of developers and discussing language/tool zealots among them (and a plea for tolerance and understanding).



What is it you do as a developer? As I see it in web dev there are a few different types: Hobbiest, Client Web Dev, Distributed Application Devs, Web App Developer (SaaS) and Corporate Dev. What do they all have in common? They're all using some sort of language to make some sort of system for somebody somewhere. That is about the last connecting factor that most of us developers actually share. [...] The crazy thing here is that most developers who are in a situation where they can use whatever system they like, often end up picking a specific tool and using it to death. This is ridiculous, as every developer should use the best tool for the job.


He talks a bit about each of the different categories of developers and where he sees their place in the world of development. He points out some of the restrictions of each type of position (required technologies, dependencies, etc) and comes to his point about their choices:



The point I am trying to make in all of this, is that while you might have really strong opinions about what language, framework, version of the framework or version of the language you use, EVERYONE has a totally different situation to you.

Jeune Asuncion: ZF1.11 + Doctrine 2 + Symfony DI Integration


In this new post to his site Jeune Asuncion shows how he integrated several technologies to make for a robust system - Zend Framework (1.11), Doctrine 2 and the Symfony dependency injection system.



Last week, I blogged about looking for a new application framework to use and more importantly the key things that I would want in one. After reading about the Zend framework, Symfony and Laravel and finding myself hesitant to use any one, I thought to myself why not get the best of each framework? So that's what I did.


He shows a bit of the code to get them to all play nicely together using the Zend autoloader to register the other namespaces and creating a Symfony DI container inside of the ZF Bootstrap and providing it as a resource. You can find more of the source involved in the integration on his github account.

2012年8月21日星期二

Community News: Latest PECL Releases for 08.21.2012

Latest PECL Releases:

Voices of the ElePHPant Podcast: Interview with Elizabeth Smith


The Voices of the ElePHPant podcast has released the latest episode of their interview series with developers and members of the PHP community. In this new episode Cal talks with Elizabeth Smith.



Cal's three questions involve her work with the PHP Mentoring project:



  • Can you give us an overview of the project?
  • How can people get involved?
  • Tell us some about the CodeConnexx conference


You can listen to this latest episode either via the in-page player, by downloading the mp3 or subscribing to their feed.

Zumba Engineering Blog: Creating bash completion to your console application


On the Zumba Engineering blog there's a new post showing you how to implement bash shell "autocomplete" with a special option for a second argument.



This weekend I saw the bash completion for CakePHP from Andy Dawson and had an idea to do the same for our service application, because we frequently forget the exactly job class or method name and add extra steps to verify these names before execute the job. I read his code, made some research and finally get our bash completion working fine.


In his case he wanted to see what things a module in the application had to offer, so he implemented a "__check__" argument that looked at the third argument and used reflection to get the methods allowed for it. Also included in the post is the bash alias you'll need to set up to get it working (and where to put it to make it cooperate).

Phil Sturgeon: CICONF - Mission Complete


In a new post to his site, Phil Sturgeon has a wrapup of CICONF (the CodeIgniter conference) that just finished in San Francisco:



This year the low-to-middle budget CodeIgniter Conference was held in San Francisco in a brilliant co-working space called Citizen Space. I didn't know at the time but this space is actually a partner of New Work City, the venue for CICON2011, so it was great to "keep it in the family".


He goes on to talk about some of the speakers that were at the even and gives summaries of the sessions as they were given. Topics included Paas (PagodaBox, specifically), Chef, Varnish, RESTful APIs and productivity with the CI framework. If you weren't able to attend, you can find slides and some videos of the event posted on its Lanyrd page.

PHPMaster.com: Message Brokering with RabbitMQ


On PHPMaster.com today they've posted a new tutorial that helps you get started adding queuing to your application with PHP and RabbitMQ.



RabbitMQ is open-source message brokering software written in Erlang. The MQ in its name refers to a standard known as Advanced Message Queuing Protocol. For our purposes, and most others, it acts as a middleman between producer (sending) and consumer (receiving) programs - it simply accepts and forwards messages. [...] Both producers and consumers can be written in any language that has an available RabbitMQ or AMQP client library. In this article, I'll demo a producer program written in PHP and a consuming program in Python.


He walks you through the installation for both RabbitMQ itself and the PHP (php-amqlib) and Python (pika) tools to use for the interfaces. There's some details on how the queuing system works and the code for the sample clients is included as well as commands to use the two clients to send/receive messages.

2012年8月20日星期一

Antonin Januska: How To Write Code Comments Well


In this new post Antonin Januska shares some reminders about what good code comments should look like - what needs to go in and what needs to stay out (you comment all your code, right?)



Code organization is a huge thing, especially for developers (because they deal with code), and often times it's a philosophical debate as to how code should be documented, if spaces should be used instead of tabs, what kind of documentation should be used and so on. Yet, what no one brings up is the dire issue of COMMENTING. We can all agree that comments are essential (and sometimes used to build half-ass documentation on big systems) but what no one really mentions is the fact that people are crappy commenters.


There's two topics he touches on that (surprisingly) it's easy for developers to forget when writing their code - "be informative" and "use consistent formatting". A lot of the issues could be helped if developers made more use of DocBlock formatting which many IDEs already have support for.

2012年8月17日星期五

PHP.net: PHP 5.4.6 and PHP 5.3.16 released!


The PHP.net site has announced the latest versions of PHP are now available for download - PHP 5.4.6 and 5.3.16:



The PHP development team announces the immediate availability of PHP 5.4.6 and PHP 5.3.16. These releases fix over 20 bugs. All users of PHP are encouraged to upgrade to PHP 5.4.6, or at least 5.3.16. For source downloads of PHP 5.4.6 and PHP 5.3.16 please visit our downloads page, Windows binaries can be found on windows.php.net/download/. The list of changes are recorded in the ChangeLog.


Bugs fixed in these two releases relate to things like bugs that were causing crashes in auto_prepend_file on the CLI web server, a segfault when DateInterval was extended, a return type on PDO and a fix for the count() call on an IteratorIterator. See the ChangeLog for the full list.

Site News: Popular Posts for the Week of 08.17.2012

Popular posts from PHPDeveloper.org for the past week:

Lorna Mitchell: Skills Allied to PHP


In this new post to her site, Lorna Mitchell shares some other skills/technologies that are "allied to PHP" and can make you a more effective (and better) developer for knowing them.



In web development, our biggest challenges are not writing code, we can do that. But getting the code safely from one place to another, with many people's work preserved, having our platform(s) correctly configured and understanding how to use them, making use of the tools in the ecosystem which will help us improve the quality of our code; these are the big challenges we face, and that's why I proposed this workshop and why I think all these topics are important.


Among the things she'll be talking about are useful things to know like effective use of version control, using a static analysis tool to evaluate your code and performance profiling. If you'd like to attend the talk and hear it all first-hand, you can find out more about PHPNW 2012 from their site.

Chris Hartjes: 5 Minute TDD


Chris Hartjes, a big proponent of testing (unit and otherwise) in the PHP community has put together a screencast to show just how easy it can be to get started with TDD (test-driven development) in PHP.



I want to talk about test driven development and show you in five minutes how to set up.


His example uses a common problem - the FizzBuzz test - and shows how to write a simple test to check the output of his "process()" method that it matches his expected results. It's a simple example, but a great (realtime) primer to how the TDD process works.

Community News: CodeConnexx Conference (Nov 8th, 9th)


There's a new conference happening in November (in Indianapolis, Indiana) brought to you by the group behind PHPWomen and EngineYard - the CodeConnexx conference.



CodeConnexx is a two-day, one track conference that aims to bring together men and women of all ages, races, backgrounds, and skillsets interested in talking about code. As we know, choosing a career as a coder comes with its own sets of life challenges, and we want to talk about those too. In short, this conference is a different kind of conference, as it connects those two pieces of the puzzle together in one event.


It's a two-day event happening November 8th and 9th and registration is now open - tickets can be purchased for $99 USD. There's lots of great topics being covered over the two days including:



  • "Getting Started Contributing to Open Source"
  • "Mentoring Developers"
  • "Everything You Ever Wanted to Know About Deployment but Were Afraid to Ask"
  • "Grokking REST"


Additionally, they're doing something interesting for those that have children and want to attend - childcare will be provided on site.

Matthew Weier O'Phinney: On Microframeworks


Matthew Weier O'Phinney has been doing some research into PHP microframeworks lately and has shared some of his thoughts in the latest post to his site.



PHP has had microframeworks for quite some time, though I only really first saw the term being used around 3 years ago. The "grand-daddy" of modern-day microframeworks can actually be traced to Ruby, however, and specifically Sinatra. [...] Since around 2009, I've seen an increasing number of new PHP microframeworks4 that follow in the steps of Sinatra and Horde. In the various implementations I've looked at, instead of using a DSL, the authors have all opted for either a procedural or OOP interface.


He gives some code examples showing how the typical routing has been handled in most of the frameworks he's seen and how they handle passing values back to the handler. He sees three use cases for frameworks like this including small, mostly static sites and APIs. He also mentions his efforts to create a microframework using components from the Zend Framework 2 (not released). He finishes up the post with some of his own conclusions about microframeworks and the lessons he learned from his efforts.

2012年8月16日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

PHPBuilder.com: Implementing User Defined Interfaces in PHP 5


On PHPBuilder.com today there's a new tutorial that talks about creating interfaces in PHP and how to use them to effectively structure your application.



Starting with PHP 5 the object model was rewritten to add features and bring PHP in line with languages such as Java and Visual Basic .NET. In this article I'll discuss interfaces, which is among the most important features in PHP 5. Other important features include visibility, abstract and final classes, methods and additional magic methods. You will learn how to define your own interfaces and how to work with them using different object model mechanisms.


The introduce you to some of the basic concepts behind using interfaces and how to create a basic one - a simple definition of a string class with one method, "getString". They then show how to extend a different example (a RandomNumber interface) and add on an additional method. He also shows how to extend multiple interfaces and integrate functionality from multiple sources, overloading and overrides.

Zumba Engineering Blog: Creating a testing interface for your API


In a new post to the Zumba Engineering blog, they share an interface they use for testing on their API (after working with something similar from another company).



They provide the documentation to the methods and I saw they have a simple interface to test their methods: Ooyala API Scratchpad. This interface was very useful while we integrate with them and I thought: "Why we don't have one interface like that for our API?" I started a page with Twitter Bootstrap to have a similar functionality, which the goal was to get an interface easy to developers see the response for multiple HTTP protocols, set the parameters, etc.


The interface uses Javascript to make requests over to a RESTful API and returns the response JSON directly to the page. It's a little bit customized to how their API works, but it's a good foundation for anyone looking to implement something similar. You can get the full code for it over on github.

Cameron McKay: Counting Syllables and Detecting Rhyme in PHP


In this new post to his site, Cameron McKay has posted a bit of interesting code - functionality that detects the number of syllables in words and checks for rhyming in phrases.



The simplicity of the rules got me thinking: how hard would it be to write a program to check if a poem stanza is ottava rima? In this article, we will write a simple ottava rima detector in PHP.


His code takes in the content and performs a few checks, one simple (length) and two custom - "is_iambic_pentameter" and "is_abababcc_rhyme". The code for these two checks are included in the post as well that, in turn, use some other functions to count syllables and vowels and use Arpabet phonetic transcription and monophthongs/diphthongs to detect iambic pentameter and rhyme.

Programmers.StackExchange.com: How can I test PHP skills in a interview?


In this recent post to the "Programmers" area of the StackExchange site, the user asks the community for help in testing a PHP developer during the interview process to asses their level of knowledge accurately.



My company needs to hire a PHP developer, but nobody has PHP knowledge in my company and we find difficult to test for PHP skills. If it were a C/Java developer I would ask him to write a quick implementation of the Game of Life, but PHP is a completely different language. I saw this test with interest. Anyone else has more suggestions?


There's several other suggestions made touching on a wide range of evaluations including:



  • Security concerns (like SQL injection)
  • Debugging/Profiling
  • Framework experience
  • Good overall development skills
  • And inks to other similar questions

2012年8月15日星期三

Community News: Latest Releases from PHPClasses.org

Chris Jones: Using the PHP CLI Webserver to Identify and Test Memory Issues in PHP


Chris Jones has a new post today showing how you can use PHP 5.4's built-in web server to help test for memory issues in your application (and the language).



Rasmus mentioned on IRC how he ran the [command line] tests: simply renaming the ".phpt" test files as ".php", and invoking them through the CLI webserver. The SKIPIF sections get executed, but that doesn't affect the desired outcome of testing multiple HTTP requests with different input scripts. [Here] are some quick shell scripts I put together to automate testing the OCI8 extension with valgrind.


He uses the OCI8 extension as an example, showing how to set up these scripts to enable the execution of the tests, fire up the web server and execute Valgrind to help monitor the memory of the execution.

Christian Weiske: PHP_CodeSniffer: notify-send report


In a new post to his site Christian Weiske shares an update he contributed to the PHP_CodeSniffer functionality to make working with and checking the validity of local PHP code easier - a notifier for PHP_CodeSniffer using the "notify-send" commonly installed in most Linux distributions.



I use emacs as IDE, and wanted to have direct feedback about the validity of my .php files when writing them. The most easy way was to add a save hook that runs PHP_CodeSniffer - but the results should be displayed in a nice, unobtrusive way. phpcs has multiple reporting modes - xml, checkstyle, csv etc. - but nothing for the desktop. I thought that notify-send would be the right fit since it is able to display pretty popup messages without getting in the way.


He also includes the details on his original objective - including it in a "on save" hook as well as providing it in a keystroke shortcut, making checking his code even easier.

2012年8月14日星期二

Community News: Latest PECL Releases for 08.14.2012

Latest PECL Releases:

Voices of the ElePHPant Podcast: Interview with Adam Culp


The Voices of the ElePHPant podcast has posted their latest interview with a member of the PHP community. This time it's with Adam Culp, an organizer of the South Florida PHP User Group.



Cal's three questions for Adam revolve around his user group participation:



  • How did you get it started and did you start the group?
  • What's the most interesting meeting we've had so far?
  • Tell us about your: mailing lists, leadership structure, your rules for sponsorships and how you found your meeting space


You can listen to this latest episode either through in-page player, by downloading the mp3 or subscribing to their feed.

PHPMaster.com: PhpStorm - Review and Give Away


On PHPMaster.com today there's a new article posted that has a review of PHPStorm, an IDE from JetBrains that focuses on providing a great experience for PHP developers and tons of features.



It's said the tool doesn't make the craft - a carpenter can drive a nail into a wooden plank using a hammer, a rock, another plank, or his forehead, but he'll rarely choose anything other than the hammer. [...] I'm talking about using a text editor versus using a full-fledged PHP-dedicated project-oriented IDE for PHP application development. Both will get the job done, but productivity-wise, one is obviously a better choice than the other.


Bruno Skvorc goes through a brief summary of what the editor is about and talks about some of the more notable features including:



  • Being built on Java (good and bad)
  • The IDE being strictly project-oriented
  • Supports the latest PHP version, including 5.4
  • Smart refactoring
  • Good intellisense support


He also mentions the plugin architecture that's included with the product and a few of the more handy plugins available. They're also running a giveaway in collaboration with the PHPStorm folks and are giving out IDE licenses and copies of SitePoint's "PHPMaster: Create Cutting Edge Code" book (rules are included in the article).

Till Klampaeckel: Continuous Integration: Automated database setup with Doctrine on Travis-CI


Till Klampaeckel has a new post to his site showing how you can use the external continuous integration system Travis-CI to handle automated database testing for your PHP app using Doctrine.



Testing is important - most people understand that by now. A lot of people write tests for their open source code already, but in-house testing is still hard. [...] While I prefer to run my database tests against a SQLite in memory database, there are these edge cases, where I work with multiple database or I write a direct query (and by-pass the ORM-magic). In these cases I need to have that database server available in my test environment! The following blog posts explains how to solve these things with Travis-CI. I will walk you through the setup on Travis-CI's business service. But most of this applies to their open source offering as well.


He's broken it up into a few different steps - the setup and configuration of the ".travis.yml" file, adding in a "composer.json" file with the needed dependencies and the recommendation of a "phpunit.xml" in your project's root. He shows how to use Doctrine's "SchemaTool" utility to generate his schema off of the comments on his entities (instead of checking in SQL). This setup them gives him access to Doctrine's EntityManager object in his tests and he can go from there. If you're thinking about doing something similar, check Travis' list of supported databases before you do anything, just to be sure.

Gonzalo Ayuso: Building a simple API proxy server with PHP


In some of his work with Backbone.js recently, Gonzalo Ayuso has been frustrated by something that's a wall for many developers wanting to work with outside datasources - the browser restriction that prevents cross-domain requests. His solution? Create a REST proxy to live on his server and pass the requests through.



Nowadays there is a header to allow it: Access-Control-Allow-Origin. The problem is that the remote server must set up this header. For example I was playing with github's API and github doesn't have this header. If the server is my server, is pretty straightforward to put this header but obviously I'm not the sysadmin of github, so I cannot do it. What the solution? One possible solution is, for example, create a proxy server at localhost with PHP.


He shares the full code for his project - basically a handler that takes the incoming request and mirrors to out to the public, remote API - request method and all. It uses some of the packages from Symfony (like the http-foundation) and wraps around cURL to handle the requests. The project is available for Composer users as well.

2012年8月13日星期一

Community News: Latest PEAR Releases for 08.13.2012

Latest PEAR Releases:

Nerds Central: Facebook Moving To The JVM


According to this new post on Nerds Central, there's been speculation that Facebook, needing even more of a performance boost than hiphop gave them, is moving into using PHP in a JVM.



The presence of Facebook engineers at the JVM Language Summit in San-Francisco along with their interest in implementing PHP using invoke-dynamic on the JVM is a the shock. The main seismic event will be nothing less than the complete removal of interpretors from main stream general purpose programming.


He talks some about the JVM environment (and the Magik project) as well as wondering about what sort of performance boost it might actually give.



So Are Facebook Doing The Right Thing? Yes! The rise and rise of Javascript over the last 4 years as shown us just how powerful JIT compilation of once interpreted languages can be. The fall and fail of complete re-writes has shown us just how unrealistic it is to completely move a working system from one language to another. Facebook has a stupid amount of PHP and so it is by far the most sensible thing to port that to mlvm. Actually it should be pretty easy.

Community News: Atlanta PHP Celebrates its 100th Meeting!


For those PHPers in the Atlanta area, there's one upcoming event that you don't want to miss - the 100th meeting celebration of the Atlanta PHP User Group (September 6th)!



We're proud to announce that we're celebrating our "100th Monthiversary" - our 100th monthly meeting - on Thursday, September 6th from 6pm to 9pm! We're planning a cookout with plenty of social time and will have Kevin Roberts presenting Pecha-Kucha style on the eight and a half year history of our group followed by Elizabeth Naramore as the featured speaker presenting on "Technical Debt". We'll also have a number of special guests from the greater PHP community, including group founder Ben Ramsey, Cal Evans, and others.


There'll be plenty of food, tech talk and giveaways at the event - not to mention Elizabeth Naramore's excellent "Technical Debt" talk. The prizes will include IDE licenses, books, gift cards, and the grand prize - a Nexus 7 tablet! Keep tuned to the Atltanta PHP site for more information as it comes.

DZone.com: GladiusDB and Firebird: Databases for Your PHP Apps


On Dzone.com Leigh Shevick continues her series looking at some of the "unknown databases" out there that PHP developers might not be aware of (but could be very useful in their applications). In this second part of the series, she looks at GladiusDB and Firebird.



In this next installment, we'll be looking at two (arguably very contrasting) databases. The first is Gladius DB, which is a flat file database written in pure PHP. The second is Firebird, another database veteran, which has features similar to some of the better-known databases, such as Microsoft SQLServer.


She gives a brief introduction of each and includes links to two resources to help you get connected to each. A bit of sample code shows how to make the connections and pull information out of simple tables (SELECTed).

Community News: Northeast PHP Conference Wrapup


The Northeast PHP Conference has wrapped up (this past weekend) and there were some great talks given and a good time had by a great group of attendees. If you weren't able to attend and want to catch up on some of the content presented at the event, check out the conference's page on Joind.in. There's links to slides for sessions like:




This is just a small sampling of the sessions, so head over to the conference's page and get the full list! Congrats to the Northeast PHP organizers for not only having a great first year but for selling out the event!

2012年8月10日星期五

Site News: Popular Posts for the Week of 08.10.2012

Popular posts from PHPDeveloper.org for the past week:

OpenShift Blog: Getting started with PHP, CodeIgniter, MongoDB, and the cloud (OpenShift)


On the OpenShift blog today there's a new post about how to get started using their service together with CodeIgniter and MongoDB to create a simple site.



In this blog post, I am going to show you how to get up and running with CodeIgniter and MongoDB. Best of all, I will show you how to get all of this deployed to a fully scalable environment using OpenShift from Red Hat.

The process involves:



  • Creating an OpenShift account
  • Installing the RHC client tools
  • Creating an OpenShift application
  • Adding mongodb to your application
  • Adding mongodb support to CodeIgniter
  • Creating a Model, View, and Controller
  • Deploy and test your application


You can then SSH into the instance and look at the database to call a "find()" and see what's there.

Mayank Kandpal: How I Start a New CodeIgniter Project


For those interested in getting started with the CodeIgniter framework, but want a more step-by-step guide to getting it up and running, this recent post from Mayank Kandpal can help.



Every other day, I develop new websites from scratch for various clients and sometimes for some of my own projects. Unless the project is really complex, I prefer to develop in CodeIgniter, a super-flexible (MVC) PHP framework which lets me develop super-quick !


He walks you through all the steps you'll need - from downloading the latest to creating the application and things like setting up logging and authentication.

SitePoint: WordPress v Joomla: Support and Community


Without a doubt, two of the most popular PHP-based projects out there are WordPress and Joomla. In this new post from SitePoint they compare the two on the basis of both their support and community (part 4 of a 5 part series).



Let's face it, an open-source content management system without a thorough user base, support system and community is destined for failure. We are comparing two giants in the CMS game here, so we already know they must be doing many things right in these departments. In this part of our series, we're going to be covering exactly what Joomla and WordPress have to offer when it comes to the support community.


Their comparison includes things like: WordPress.org vs Joomla.org, their respective support forums, other initiatives surrounding them and places you can find others to help you in your WordPress or Joomla work.

2012年8月9日星期四

Site News: Blast from the Past - One Year Ago in PHP

Here's what was popular in the PHP community one year ago today:

MaltBlue.com: Hot to Use the Zend Form ViewScript Decorator in All Modules


On his MaltBlue.com site today, Matt Setter has a new post showing you how to use the Zend_Form ViewScript decorator in your Zend Framework-based application's forms.



If you've been using Zend Forms for any length of time, you'll know just how flexible and configurable they are. [...] We can, as I'm quite fond of, use the ViewScript decorator. This allows us to have nearly 100% control of the configuration of the look and feel of our rendered forms.


The ViewScript decorator lets you have full control over the layout of your form, letting you use a view (file) to define the markup for the form and injecting your elements into it. There is an issue with using the form in other modules though - it can't find the view file by default. The solution is to pass in a viewModule when using the form, showing it where it can find the view.

Zumba Fitness Engineering: Using Application Events to Hook in Plugins


In this recent post on the Zubma Fitness Engineering site, Chris Saylor looks at using events in your applications to hook in plugins to easily (and dynamically) enhance functionality.



In many instances, having a plugin system (even for closed-source applications) is a convenient and safe approach to adding functionality to a product. It minimizes risk by not having to modify the core of the source. In this article, I'll be discussing how we implemented a plugin system for our cart software to allow for plugins.


Its implemented a bit like the Observer design pattern - you "register" the listening event which can then be activated by a "trigger" method with the event's name. These events are stored in a registry (static) so they can be accessed across the application.

Sherif Ramadan: Finally Getting finally In PHP?


In this recent post to his site Sherif Ramadan looks at a proposal that's currently under view (RFC) to add the "finally" keyword to PHP.



It's quite possible that PHP may finally be getting the addition of the finally block in its try/catch block. [...] It also solves a simple, but overlooked problem for the developer. With finally we offer the user-space code a chance to do any clean up work that may be necessary after a try block has terminated execution and with clear semantics.


He includes a use case for this feature - an example showing exception handling on multiple levels and writing to log files when the cleanup of the exception is finished (without the potential for another method to trigger the exception itself). "Finally" allows you to take this logic out of the exception handling and put it at the end, removing the possibility of it triggering an exception for the wrong reason. There's a few other examples showing some other quirks with its usage - like calling die will not make it end up in the "finally".

2012年8月8日星期三

Community News: Latest Releases from PHPClasses.org

Gonzalo Ayuso: Book review: CouchDB and PHP Web Development


Gonzalo Ayuso has posted a book review of a Packt Publishing book "CouchDB and PHP Web Development":



Finally the new Book "CouchDB and PHP Web Development" written by Tim Juravich is ready an in my hands. It was my first experience as technical reviewer. The author contacted me by email and the editor sent me book chapters to review. Basically I gave my opinion, I test the code and I hunt for bugs. It was a great experience. Now is really cool to see the book in my hands.


Overall, he gives it a positive review (for a beginner level book) and points out a few things that can help make the reading experience better, like the "Time for Action" sections. He also was happy with the author's choice of using the Twitter Bootstrap for the interface of the sample application.

Laura Thompson: The dark craft of engineering management


Laura Thompson has a new post to her site about the "dark craft" of engineering management and of her thoughts as to why it's as much a "craft" as writing the actual code.



Why is management a craft? It's a craft for the same reasons engineering is a craft. You can read all the books you want on something but crafts are learned by getting your hands in it and getting them dirty. Crafts have rough edges, and shortcuts, and rules of thumb, and things that are held together with duct tape. The product of craft is something useful and pleasing.


She goes on to fill out her description of what it really means to manage a development group including providing devs with the resources they need to master the subject and allowing them the autonomy to solve problems without having to be involved in every decision. You can read the rest of her thoughts here.

Project: PHPHint.org - Online PHP Code Analysis


Klaus Silveira has submitted a project he's come up with to help PHP developers detect problems in their code via a web-based application - PHPHint.org.




PHPHint is a community-driven, quick and easy to use, online tool that analyzes your PHP code and looks for potential errors, lack of best practices and code smell. It also allows you to clean your code automagically.



It was created to spread the work about the PSR standards and the PHP-FIG group, the importance of getting rid of code smell and applying to standards.




Since it is an open source project, you can help contribute if you'd like to see improvements to the service. It's great that it takes the relatively new PSR standards (PSR-1 & PSR-2) into account when analyzing the code too.

Project: Major Codeception Update (BDD in PHP)


The Codeception project (BDD testing in PHP) has gotten a major update to its feature set and has bumped up to v1.1:



Many core classes were refactored to solve the common issues and reduce the level of dark magic inside. Only white magic left. And that's really cool 'cause you don't need to study to source code to implement your custom hooks now. Codeception is rapidly evolving to be the professional testing tool, ready to use by testsers and developers through out the PHP world.


Improvements in this large update include an update to the method of test execution, "grabbers" (helper methods that can extract content from tests), the introduction of XPath support to locate items in the content pulled into the test and the integration with unit testing. Upgrade instructions are also included.

2012年8月7日星期二

Community News: Latest PECL Releases for 08.07.2012

Latest PECL Releases:

Web and PHP Magazine: Issue #5 Released - "On Your Marks"


The latest issue of the Web and PHP Magazine has just been released - Issue 5. In this issue you'll find:



  • #Trending: What's hot and what's not in the PHP and web dev community at the moment
  • An interview with Zeev Suraski
  • A Look Ahead to ZendCon 2012
  • "5 Reasons To Maximize Your Use Of PHP's Built-In Feature"
  • Stefan Priebsch On Soccer.


As always, you can download the issue for free to get the PDF version or you can download the iPad application and get the latest issues there.

Voices of the ElePHPant Podcast: Interview with Josh Lockhart


The Voices of the ElePHPant podcast has released their latest interview with a PHP community member - Josh Lockhart, creator of the PHP - the Right Way project.



Cal's three questions center around his involvement in this project:



  • Why did you start "PHP - The Right Way"?
  • What makes "PHP - The Right Way" different from other beginner PHP resources out there?
  • Who can contribute to "PHP - The Right Way"?


You can listen to this latest episode either through the in-page player, by download the mp3 or subscribe to their feed.

NetTuts.com: Let's TDD a Simple App in PHP


On NetTuts.com there's a new tutorial that wants to show you a practical approach to using TDD in your development (test-driven development) through a simple project.



In this tutorial, I will present an end-to-end example of a simple application - made strictly with TDD in PHP. I will walk you through each step, one at a time, while explaining the decisions I made in order to get the task done. The example closely follows the rules of TDD: write tests, write code, refactor.


They start off by defining what TDD is (three core rules) and how the PHPUnit tool makes it easy in PHP. They use NetBeans in their examples, but it can be done similarly in any other ID (or command line). They start with some first tests - checking for word wrapping on short string and empty string handling.