2011年4月29日星期五

Site News: Popular Posts for the Week of 04.29.2011

Popular posts from PHPDeveloper.org for the past week:

Ibuildings techPortal: DPCRadio: Technical Writing


On the Ibuildings techPortal they've posted a new episode of their recordings from the Dutch PHP Conference 2010, DPCRadio - a recording of Elizabeth Naramore's session Technical Writing.



If you've had an idea for writing a blog post or article, but you're not sure where to start, this talk is for you! Maybe you've had difficulty effectively documenting your code, or communicating your ideas to non-techies. This talk will help you, too! In this fun and informative session, we'll discuss the basics of writing and clear communication through the written word. We'll also talk about strategies for keeping your writing interesting and informative at the same time. Finally, we'll discuss resources for improving your writing skills in the future.


You can either use the in-page player to listen or you can download the mp3 to listen wherever you'd like.

Hannes Magnusson's Blog: There is an app^Wppa for that


Hannes Magnusson, in an effort to make it easier for developers to play with the latest shiny features of the current PHP development, has created a PPA for the latest daily status of the PHP project's trunk line of code.



There is still no public "development preview" or alpha release, but that doesn't mean we can't play around with it, report bugs, ensuring our apps still properly work with it etc etc etc. It is however a bit annoying needing to "go old-school" and fetch a snapshot and build it yourself though.


If you'd like to try it out for yourself (the generated Ubuntu packages), you can get more information over on the Launchpad page for the project. As always, feedback is welcome on the PHP internals list about your experiences.

Symfony Blog: Symfony2: Getting easier


On the Symfony blog there's a new post about how Symfony2 is "getting easier" thanks to some recent changes with improved error handling and simpler configuration options.



With the release of the first beta approaching fast, our main focus has switched from adding new features to polishing existing ones. [...] Recently, Ryan and I have spent our time tweaking error messages, simplifying the code and the configuration, adding more documentation, and making things more consistent throughout the framework. The goal is to ease the learning curve and make things that people will need on a day to day basis simpler.


The changes they've made include three updates - better Twig error messaging, better configuration error messaging and some helpful changes to the Doctrine configuration to allow for auto-mapping of connections when the traditional one-database setup is used.

2011年4月28日星期四

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

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

Zend Developer Zone: Announcing the April 2011 Zend Framework Bug-Hunt


On the Zend Developer Zone there's a new post from Ralph Schindler announcing this month's bug hunt days for the Zend Framework project - April 28th (today!), 29th and 30th.



Now that you're done paying the Tax Man (for the North Americans reading this blog post), it's time to pay it forward by helping an open source project close some issues! For those who haven't put the reoccurring event in their calendar, this announcement is for you. [...] For those of you unfamiliar with the event, each month, we organize the community to help reduce the number of open issues reported against the framework.


He mentions the top contributor of last month's bug hunt (Benoît Durand) and some handy links you can use to get involved - the current bug list, how to sign up for a CLA (required to contribute) and a guide for the beginners out there.

Jeremy Brown's Blog: A Conversation About REST


As mentioned in this new post to his blog Jeremy Brown has put together a presentation he calls "A Conversation about REST", a discussion that centers less around the implementation of REST and more about the concepts needed to fully understand it.



REST is a set of principles and not a specification, so as such you have freedom in how to develop your API. This freedom can lead to confusion though, as it's hard to find concrete examples of its implementation. This presentation explained what REST is and also presented a variety of topics and questions you will certainly come across while implementing your API.


You can watch a video of this great presentation (as taken at a Club Ajax meeting in Dallas) here and can follow along with his slides off of SlideShare. He also links to a great image that gives a flow overview of the possible paths a REST request could take.

Shay Ben Moshe's Blog: PHP's native array vs SplFixedArray performance


Shay Ben Moshe has put together a quick post today where he benchmarks array handling performance differences between PHP's native array and the newer SplFixedArray data structure that's a part of the Standard PHP Library that comes with any recent version of the language.



In PHP, arrays are one of the most fundamental data structures.
We use them everywhere.
They are very flexible, because they are implemented as associative arrays, and therefore let us use both string and integer keys. They are also unlimited in size, in most languages arrays are fixed-sized, but this is not the case in PHP. With that in mind, there still is a drawback. It damages performance. The solution for this problem may be SplFixedArray. But, it is not a perfect solution.


He points out two major differences - the SplFixedArray is, well, a fixed size and the fact that it can only use integer keys (no associative arrays here). He created three tests to compare the performance of the two:



  • Writing data to the array
  • Reading data from the array
  • Getting a random value from the array


Each of these are measured in terms of runtime and/or memory usage. If you'd like to try out the tests for yourself, you can download the files needed. I won't cover the results of the tests here, though - you'll need to visit the post for that!

2011年4月27日星期三

Community News: Latest Releases from PHPClasses.org

Stefan Koopmanschap's Blog: Removing stylesheets in symfony 1


Stefan Koopmanschap has a quick post to his blog with a handy, not immediately obvious tip for the Symfony users out there - how to remove site-wide stylesheets in a Symfony application so it's not loaded automatically.



Today I encountered a situation I've not encountered before: I have a project-wide stylesheet that should be used for everything, except one specific module that has different (brandable) stylesheets. I created a view.yml for this module with a different stylesheet, but of course the configuration files are merged so it doesn't actually overwrite the main stylesheet file. And this wasn't really what I needed here.


His technique involves a change to the main view.yml configuration file with a special syntax to remove the CSS file with a negation. A snippet is included to illustrate. You can find out more about view configuration in this chapter of the "Definitive Guide to Symfony".

Stuart Herbert's Blog: Last Call For Requirements For A PEAR Channel Aggregator


If you're still interested in contributing your ideas and feature requests for a PEAR channel aggregator, Stuart Herbert wants to know (last call before the development starts).



There's already been a sizeable response so far, but if you haven't had your say yet, please head on over and leave a comment soon. I'll write up a summary of the suggested requirements on Monday.


The idea behind the aggregator is to provide a single place for developers to look (besides the PEAR site, of course) for PEAR packages they might find useful. The key here is that the aggregator would be bringing together the independent channels out there and making them simpler to find. Feature suggestions so far include: showing where the library lives (like github or bitbucket), creating a proxy channel for a "single install" location and customized lists of a user's "in use" and "tracked" packages.

2011年4月26日星期二

Community News: Latest PECL Releases for 04.26.2011

Latest PECL Releases:

Community News: Dutch PHP Conference Announces Final Keynote Speaker - Aral Balkan


The Dutch PHP Conference has officially announced their final keynote speaker (finishing out the schedule) - Aral Balkan will be speaking on "The Art of the User Experience".



We believe the schedule already has a lot to offer the way it is, but we still had one annoying "to be announced" slot on the Friday morning: the opening keynote! With only three weeks to go we are proud to announce that the DPC will be kicked off by one of the most talented speakers out there: Aral Balkan!


He'll talk about making "beautiful, delightful and fun things" as a part of the experience your user has with your applications. If you haven't gotten your tickets yet, be sure to grab them now. There's only three weeks left until the event! Full tickets cost 695 Euro and the half-tickets (just conference day or just tutorial day) are 375 Euro.

Evert Pot's Blog: Numeric string comparison in PHP


In this new post to his blog Evert Pot reminds you (the PHP developer) about the loose and strict typing checks that you need to do when checking the values of your variables and never just assume. PHP's loose typing tendencies can cause issues if you're not paying attention.



As long as you make sure you always use strict checking (=== and !==) where you can, and fall back to the loose checks when you must. As a PHP developer, I think it's very important to understand and memorize exactly how these work, whether you're writing new code, or maintaining existing code.


He points out a specific example of some code that seems counter-intuitive when you compare how it reads and how it actually works (strings converted to floats and evaluated)



The moral is: always do strict checks when you are able to.

2011年4月25日星期一

Community News: Latest PEAR Releases for 04.25.2011

Latest PEAR Releases:

PHPBuilder.com: Use PDO to Access Just About Any Database from PHP


New on PHPBuilder.com there's a tutorial from Leidago Noabeb about using the PDO functionality that comes installed on many PHP platforms out there to access just about any database you might need to work work. This includes technology like MySQL, DB2, SQLite and PostgreSQL.



PHP Data Objects, or "PDO" as it is commonly known, is a lightweight database abstraction layer that is arguably the best, at least in terms of speed. A great deal of this speed is owing to the fact that the PDO extension was compiled with C/C++. The extension became available in PHP5, and as with any other database abstraction layer, its aim is to provide a uniform interface to access a variety of databases. This is also a way for developers to create portable code for a variety of platforms.


The tutorial shows you how to find the enabled PDO connection types for your installation (and where to go if you have access to turn more on or off). They show an example connection - in this case, to a MySQL database - and how to run a query or two using this new resource.

Eran Galperin's Blog: Breaking Down The PayPal API


In a recent post Eran Galperin takes a look at the PayPal API and breaks it down into smaller, easy to digest chunks to show you how to you can implement it in your application. Be warned, though - he mentions that it's the "among the worst API he's ever had to deal with" for several reasons.



PayPal is the most popular platform for receiving online payments. The relative ease of opening a PayPal account and receiving payments compared to opening a merchant account for a traditional payment gateway is the number one reason, and another is the comprehensive API they provide for their payment services. [...] There doesn't seem to be any better alternatives currently, so hopefully this guide will help ease the pain for some of you out there taking your lumps working the API into your applications.


Eran starts with a look at some of the different payment options, express, direct, recurring and mass, and what they're good for. From there, it's off to the code with his tool of choice being curl to make it simpler to make requests with headers, content and fetch the response message. He's put together a little custom function to make it easier to reuse. As an example, he shows how to make an Express Checkout request by grabbing a token and redirecting to the PayPal site for handling.

2011年4月22日星期五

Site News: Popular Posts for the Week of 04.22.2011

Popular posts from PHPDeveloper.org for the past week:

Eric Hogue's Blog: Late Static Binding


Eric Hogue has a recent post to his blog looking at one of the more tricky aspects of the latest versions of PHP (the 5.3.x series) - late static binding. In a nutshell, late static binding (LSB) lets static classes and methods work more correctly than before. Eric gets into a bit more detail than that:



It came out almost 2 years ago, but it to me that many programmers around me have no idea about it. Myself, I have learned about it around 6 months ago. The PHP documentation defines late static binding as a way to "reference the called class in a context of static inheritance." This definition didn't really help me the first time I read it. Fortunately, there are more explanations in the documentation, and there are good examples. If you haven't, you should read it.


To clarify, he includes a code snippet showing the use of the "static" keyword to correctly reference a static method. He also includes in interesting bit about when's a good time to use it.

2011年4月21日星期四

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

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

Voices of the ElePHPant: Interview with Ed Finkler


The Voices of the ElePHPant podcast has posted their latest episode - an interview with Ed Finkler, best known for his work on the Spaz Twitter client.



Cal interviews Ed and asks him his "three questions" about this Open Source project (Spaz):



  • At what point did you realize you couldn't do it all yourself and what was the first role you created for someone else?
  • What ways do you use to communicate with your developer community and which works the best?
  • Other than coding, what's the most fun part about running an Open Source project?


As always, you can either listen to this latest episode in-page, by downloading the mp3 or by subscribing to feed.

Script-Tutorials.com: How to parse web pages using XPath


On the Script-Tutorials.com site there's a new article showing you how to use XPath to parse web pages, complete with screenshots of the page and the code to make it happen.



Today I will tell you how you can make parsers of remote HTML pages (in PHP). In this article I will show you how to perform xpath queries to Web pages. XPath - a query language to elements of xml or xhtml document. To obtain the necessary data, we just need to create the necessary query. For the work, we also need: browser Mozilla Firefox, firebug and firepath plugins. For our experiment, I suggest this webpage Google Sci/Tech News. Of course you can choose any other web page too.


They provide two demos and a downloadable package with everything you need. The script pulls in the page as a DOM document (which works as long as it's correctly formatted XML) and spits back out the matches from a few different XPath expressions. There's all sorts of sites out there that can help you with examples of other XPath expressions and syntax.

2011年4月20日星期三

Community News: Latest Releases from PHPClasses.org

Brian Swan's Blog: How to Use the Storage Emulator with the Windows Azure SDK for PHP


In a recent post to his blog Brian Swan shows you how to use the Storage Emulator for Azure with PHP via their provided SDK. It's a quick post but it has a helpful code snippet if you've been struggling with getting it set up.



This is a short post to address this question: How do I use the local Storage Emulator (formerly known as Development Storage) when using the Windows Azure SDK for PHP? The Windows Azure Command Line Tools for PHP provide an option for running an application locally in the Compute Emulator, but I didn't see an option for using the local Storage Emulator. As it turns out, the answer is very simple, although somewhat difficult to find.


The trick is to omit the constructor parameters when creating a new table/blob/client to get it to create things locally instead of on your Azure instance. He also includes a set of links that can help fill in some of the gaps in the whole Windows Azure deployment process.

DZone.com: What I Love/Hate About PHP


On DZone.com today there's a new post from Eric Hogue talking about the love-hate relationship he has with PHP (as a developer of five years with it).



I have been programming in PHP for 5 years now. I did not choose this language, I had to learn it to work on the code of the company my bosses bought. Since I started, I heard many rants about how bad PHP is. Some where valid, but a lot of them are just blaming the language for bad code written by bad programmers. I am by no mean an expert in programming languages or PHP, but here is my take on the language I use every day.


His "good" section mentions one of the most popular things about the language - its quality of documentation. He also talks about the interactive shell and the community that surrounds the language. In the "bad" category, though, he points out things like the low barrier for entry ("a blessing and a curse"), the changing order of parameters in function calls and that a constructor of a child class doesn't automatically call the parent's constructor.

2011年4月19日星期二

Community News: Latest PECL Releases for 04.19.2011

Latest PECL Releases:

Voices of the ElePHPant: Interview with Josh Butts


On the Voices of the ElePHPant podcast, Cal has posted his latest interview, this time with Josh Butts, an organizer of the PHP user group in Austin, Tx



Cal's "three questions" for Josh are:



  • What is the most difficult aspect of running one of the larger PHP user groups?
  • What is the most successful thing you've done in the group?
  • How do you guys manage to play nice with the other technology groups in Austin?


As usual, you can either listen in-page, by downloading the mp3 or subscribing to their feed.

Lukas Smith's Blog: Symfony2, what I think is still left to do


Lukas Smith has posted some of the things he thinks the Symfony2 framework still has left to do before it can be released in a stable form.



The goal of this blog post is to number one serve me as a todo list of stuff that I personally think needs to be fixed before Symfony2 can be released. Hopefully it will also entice some people to help out with these tasks. I am focusing on the medium to large tasks. There are of course still a fair number of smaller fixes that need to be applied.

Items on the list include:



  • switch Security/Validation components to using message key's rather than full sentences
  • Assetic documentation
  • Adding a DIC aware Serializer
  • Better support for SSL'ed urls and assets
  • ttempt to automatically determine service scopes

2011年4月18日星期一

Community News: Latest PEAR Releases for 04.18.2011

Latest PEAR Releases:

Hannes Magnusson's Blog: up2date PHP5.3 packages for Ubuntu


In a new post to his blog Hannes Magnusson mentions that the PHP packages for Ubuntu linux installs are woefully out of date and can make a developer's live even more difficult than it already can be. It help ease the situation a bit, he's figured out how to provide custom PHP 5.3 packages to anyone who wants them through a service called Launchpad.



Launchpad makes it really easy to provide your own custom packages, and even has a vast build farm to build packages automatically for different architectures and different Ubuntu releases. The only down side is it doesn't build rpm packages.. Thats fine by me, but that would be really useful for those wishing to deploy on a RedHat based distro.


He took the current package and pulled out a lot of the setup to make a "vanilla" installation. You can then look over at the PHP 5.3 PPA he's provided on his Launchpad account and grab this most up to date package.

Robert Basic's Blog: Grouping Zend Framework controllers in subdirectories


Robert Basic has a new post today showing you how you can group your controllers in your Zend Framework application into subdirectories for easier organization.



Thanks to a discussion on the Zend Framework mailing list I learned about a new feature, a feature that allows for grouping action controllers in subdirectories! Well, this is more of an unknown and undocumented feature than new, as it is the part of the framework for at least 3 years. Why am I so hyped about this? Because it allows for better code organisation on larger projects. Heck, it might be useful on smaller ones too.


He gives an example of how it might be laid out and a few helpful hints he learned when trying it out:



  • The subdirectory separator in the URI is the underscore and not the slash.
  • The subdirectory name is uppercase: Subdirectory, not subdirectory. In the URI it's lowercase.
  • The view directories for these subdirectories are lowercased, and not uppercase.

2011年4月15日星期五

Site News: Popular Posts for the Week of 04.15.2011

Popular posts from PHPDeveloper.org for the past week:

Lorna Mitchell's Blog: Script for Database Patching at Deploy Time


As a part of one of her projects, Lorna Mitchell had a need to deploy database patches as a part of her overall deployment process. Obviously, doing this manually every time can be a hassle so she came up with a script that does the work for her (based on a patch_history table).



My current project (BiteStats, a simple report of your google analytics data) uses a basic system where there are numbered patches, and a patch_history table with a row for every patch that was run, showing the version number and a timestamp. When I deploy the code to production, I have a script that runs automatically to apply the patches.


The script uses the number-based patch names (such as patch1.sql) and finds the latest ones that haven't been applied based on the highest values for the patch_number column in the database. This number is updated by the patches themselves when they're run to avoid any confusion in the script itself. She has it running as a part of her phing build process as a part of a Zend Framework application.

Robert Basic's Blog: A hack for Zend Framework's translated route segments


Robert Basic has put together a new post to his blog about a hack he's found for the Zend Framework translated route segments when a "gotcha" popped up when he was trying to use them in a multi-language website.



The web site's default locale, language, is English. If the user has no locale in the session/cookie, she, or he, will get the English version of the web site. [...] But! If the user's first visit is on the http://example.com/vesti URL ("vesti" is "news" in Serbian), the router can't route that because it depends on the locale and the default locale is English and not Serbian, thus directing the user to the 404 page.


To get around this issue he created a front controller plugin that fires in the postDispatch hook to change the locale manually if the current request's isn't found to be English. It then redirects the user to the correct location for the new language and things proceed normally.

2011年4月14日星期四

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

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

Voices of the ElePHPant: Interview with Ryan Weaver


The Voices of the ElePHPant podcast has returned back to its usual interview format in this latest episode, an interview with Ryan Weaver an organizer of the Nashville PHP user group



Cal's "three questions" for Ryan about getting involved in local user groups:



  • What advantage do you get out of the labor you put into the Nashville PHP user group?
  • When you start looking for speakers, how do you find them?
  • If you had to pick one piece of advice to give to other user group leaders, what would it be?


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

Christian Weiske's Blog: A MIME type for .php files


Christian Weiske has a recent post to his site looking at something most PHP developers don't even think about when serving up their scripts - the MIME types for PHP files.



While setting some svn properties at work, we wondered about the correct MIME type for .php files.


He found several in the official IANA list including "text/php", "application/php" and "application/x-http-php" - all valid but none of them considered a standard. He talks about the ones supported by linux distributions (like Debian/Ubuntu) and some reasoning that might make "application/php" the best choice of the list. He points out some downsides to the choice, though, including the fact that something starting with "application/" should considered "machine readable" only despite PHP just being text.

2011年4月13日星期三

Community News: Latest Releases from PHPClasses.org

Till Klampaeckel's Blog: A roundhouse kick, or the state of PHP


Inspired by some of the recent discussions in the PHP community about the future of the language and the software that uses it, Till Klampaeckel has posted some of his own thoughts on the matter.



Last week the usual round of PEAR-bashing on Twitter took place, then this morning Marco Tabini asked if PHP (core) was running out of scratches to itch. He also suggests he got this idea from Cal Evan's blog post about Drupal forking PHP.


Till talks about a few different points others have made in their comments and tries to clear a few things up - the state of PECL, Drupal and PHP (and forking), PEAR and how some of this infighting might be doing more harm than good for the community.

Community News: FrOSCon Call for Papers Announced


This year's FrOSCon conference has officially opened their Call for Papers for this year's event. It's happening August 20th and 21st at the University of Bonn-Rhein-Sieg.



The sixth Free and Open Source Software Conference in Sankt Augustin, near Bonn, will take place on August, 20th and 21st 2011. We are looking for submissions in order to again have a comprehensive and interesting program. You can find all you need to know at http://www.froscon.de/en/program/call-for-papers.html. You can find the interface for submitting talks here. This year, we test a new system for the submissions. [...] The deadline for submissions is May, 23rd 2011.


They're looking for sessions that cover a wide range of free and open source software topics such as: operating systems, development, security, legal issues and education. They're particularly interested in topics surrounding devops, desktop innovation and how projects are "finding new blood" to help them thrive.

2011年4月12日星期二

Community News: Latest PECL Releases for 04.12.2011

Latest PECL Releases:

Brian Swan's Blog: Updating PHP Settings in Windows Azure


Brian Swan has a new post today looking at how you can update some PHP settings in your Windows Azure instance - an alternative to redeploying your every time your php.ini file might need an update.



I came across this question on Twitter last week: "How can I turn display_errors on for an application that is running in Windows Azure?" I have to admit that I was stumped. The only thing I could think of was to re-deploy the application with an updated php.ini file. But, I happened to mention this question to Ben Lobaugh who suggested a very simple idea: Store your PHP settings in some durable store external to your application as key-value pairs, then loop through the settings and update them with the ini_set function when a page loads.


He puts a big disclaimer on his suggestion, noting that it's "a hack and only a hack" and can be useful for someone still learning how to work with Azure and deployment. He shows how to use a Table storage to save the values and make them easier for the application to grab at runtime. Using the tools from their SDK, fetching and setting those values is a simple process. An idea like this, while convenient, could potentially cause performance issues down the line, do be careful with this recommendation (and be sure to load test).

Chris Hartjes' Blog: Book Review -- Easy PHP Websites with the Zend Framework


Chris Hartjes has posted a book review of one of the latest books from Jason Gilmore, "Easy PHP Websites with the Zend Framework" (published March 2011)



At 240 pages I wouldn't say this is the type of book that you can really read cover-to-cover at a rapid pace. I think it is more suited as a very long and expanded HOWTO for building an application from scratch. I was also pleased to see that Jason had made the commitment to pushing Test Driven Development by having the reader write tests for the site they were building as they went along.


Chris goes on to talk about the contents of the book and how it uses a project (creating a social networking app called GameNomad) to help squeeze as much about the Zend Framework into your head as possible. In his opinion, the book is a good resource for both beginning and intermediate users of the framework and can potentially be used as more of a reference for different takes on common problems.

2011年4月11日星期一

Community News: Latest PEAR Releases for 04.11.2011

Latest PEAR Releases:

Courtney Robinson's Blog: Apache Cassandra+PHPcassa+Code Igniter = large scale PHP app in 5 minutes


In a new post today Courtney Robinson shows how the combination of Cassandra, PHPcassa and CodeIgniter can be used to create a large scale PHP application in five minutes .



I'm working on a new project, migrating an existing site using custom code with a very monolithic design on top of MySQL. Design goals : Implement all the same functionality using a manageable framework with a small footprint on a distributed NoSQL database. Small footprint? I'm thinking Code Igniter (CI)...Distributed NoSQL (my favorite part)? I'm thinking Apache Cassandra!!!


The basic idea was to have the CodeIgniter database object (the $this->db) available but still allow the application access to the Cassandra database as well. PHPcassa was the answer. One created configuration file and a custom database library later and the tool was implemented into the CodeIgniter structure.

Query7.com: Why You Should Be Using A PHP Framework


On the Query7.com blog, Logan has posted his opinion on how you should be doing your development on sites that are more than just one or two pages - you should be using a framework.



Frameworks should be used when constructing web applications. Any application that involves a database, forms, sessions, cookies or a remote service (such as Twitter or Facebook) will benefit from being powered by a framework. There is no need to use a framework for a website that has only one or two pages, nor for command line utility scripts.


He lists some of the common features frameworks provide including database abstraction, caching, form management, authentication and internationalization. He also includes some of the more general benefits you get from using frameworks like portability, shorter development time, application security, plugins/module support and the enforcement of good coding standards (depends on the framework, obviously).

2011年4月7日星期四

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

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

Oracle Technology Network: Scaling a PHP MySQL Web Application, Part 1


The Oracle Technology Network has posted the first article in a series by Eli White looking at building a scalable PHP/MySQL web application.



Hopefully the most important lesson you can learn here is to understand what you will need to do to scale in the future. By knowing this, you can do only what you need at each phase of your project without "coding yourself into a corner", ending up in a situation where it's hard to take the next scalability step. [...] In this two-part article I will share some of the lessons learned, and take you step by step through a standard process of scaling your application.


He touches on a few different topics in this first part of the series - performance vs scalability, tuning your PHP installation and database load balancing through master/slave replication.

Community News: Two Week Reminder for PHP Community Conference Tickets


As a reminder to all of those out there wanting to attend this year's PHP Community Conference - it's only two weeks until the event, so you better register soon!



The PHP Community Conference is a two-day event. We kick things off with a tutorial day that will introduce you to tools and ideas that you can use in your code right away. The second day will consist of presentations that will inspire you to create something new with PHP.


The conference is happening April 21st and 22nd in Nashville, TN and tickets for the two-day event are $300 USD. There'll even be a Pecha Kucha event where two iPad2s will be given away. You can find out more about the schedule and the rest of the conference on the event's website.

DZone.com: Solarium PHP Solr client


New on DZone.com today there's an article from Bas De Nooijer talking about a new tool he's created to allow PHP to work directly with Solr (the popular searching platform from the Apache project) as a result of research he'd done from a previous article. The result is < href="https://github.com/basdenooijer/solarium">Solarium, an open sourced PHP client for Solr.



I've worked on a lot of Solr implementations in PHP applications. There are multiple solutions: manual HTTP requests, the solr-php-client library, custom implementations etcetera. However they all have one issue in common: they only handle the communication with Solr, many other important parts like query building are not covered at all. And the parts that are covered are usually over-simplified. [...] At first I developed it as a library for my own projects, but I've decided to turn it into an opensource project. The project is called 'Solarium' and can be found on github: https://github.com/basdenooijer/solarium


You can find complete details about the project over on its wiki including basics concepts of query flow and using the ping/select/update query methods to access your Solr server.

2011年4月6日星期三

Community News: Latest Releases from PHPClasses.org

DZone.com: PHP Quick Reference


On DZone.com today there's a new post from Chris Shiflett sharing some timeless advice from an older copy of a PHP Quick Reference (published in 2009) about performance and security.



While cleaning out my desk, I found an old copy of a PHP Quick Reference I helped make a few years ago. On the front page are a few performance and security tips that I thought I'd share. (Performance tips are from George Schlossnagle.)


Performance tips include profile early/profile often, cache when possible and don't over-optimize. The security hints include some of the usual suspects - trust nothing, filter input/escape output and use prepared statements.

PHPBuilder.com: The PHP Fat-Free Framework: Slim Down Your PHP Development


On PHPBuilder.com Jason Gilmore has posted another article in his series looking at lightweight frameworks. In this latest article he looks at the PHP Fat-Free Framework, a PHP 5.3 framework the comes bundled in a single 55KB file.



If you're keen to start capitalizing upon the great framework-oriented features you've heard so much about but aren't yet ready to invest the significant time required to master one of the more involved solutions, consider investigating one of the lightweight solutions such as the PHP Fat-Free Framework. In this article I'll show you just how easy it is to get started building Web sites using this deceptively tiny (55kB) framework.


You'll need a PHP 5.3 install to get the framework working - several bits in its core use 5.3-only features. He shows how, at its simplest, the framework can be used to generate "clean URLs" even if it just routes to HTML files. Next is setting up dynamic routing then building page templates and MySQL integration. If you're looking for more detail on the framework and what it has to offer, visit the project's page on SourceForge.

2011年4月5日星期二

Community News: Latest PECL Releases for 04.05.2011

Latest PECL Releases:

CatsWhoCode.com: 10 super useful PHP snippets


The CatsWhoCode.com blog has a new post today with what they call super useful PHP snippets that could help you out in a pinch.



Having the right code snippet at the right time can definitely be a life saver for web developers. Today, I've compiled 10 really awesome PHP code snippets that will, I hope, be very helpful in your forthcomming developments.

Their list of ten includes bits of code for:



  • Super simple page caching (file-based)
  • Convert seconds to time (years, months, days, hours...)
  • Get current weather using Google API
  • Get latitude and longitude from an address
  • Save url to PDF

Ian Barber's Blog: Benford's Law


In a recent post to his blog Ian Barber looks at applying Benford's Law in PHP to determine if the dataset you're working with is "real" or not.



Benfords Law is not an exciting new John Nettles based detective show, but an interesting observation about the distribution of the first digit in sets of numbers originating from various processes. It says, roughly, that in a big collection of data you should expect to see a number starting with 1 about 30% of the time, but starting with 9 only about 5% of the time.


He pulls data from the data.uk.gov site to illustrate and includes a simple PHP script to run through the data looking scoring it with a "Benford" rating. He plots these on a graph along side the data to show the (almost exact) match between the data and the Benford numbers. You can find more details on the law on Wikipedia.

2011年4月4日星期一

Community News: Latest PEAR Releases for 04.04.2011

Latest PEAR Releases:

HashBangCode.com: Revisiting filter_var() and FILTER_VALIDATE_URL


From the HashBangCode.com site today there's a new post that revisits filtering with the filter_var function included with the language. The focus in this article is specifically in validating URLs with the FILTER_VALIDATE_URL flag.



Quite a while ago I looked at using the filter_var() function to validate URL's using the FILTER_VALIDATE_URL flag and someone pointed out recently that this function has not only changed since the initial release, but that a number of flags can be added to change the way that this function works.


He lists some of the other flags that are now available that can be used in conjunction with FILTER_VALIDATE_URL to get more fine-grained in your filtering - checks on things like a required scheme, hostname and query string. He includes some code with a set of URLs to run through some tests and output as a table with the pass/fail rank of each URL value. You can see the resulting output here.

Brandon Savage's Blog: Validation Blind Spots Hurt Real Users


In a new post to his blog Brandon Savage talks about how some of your current validation rules (and restrictions on input values) could be causing blind spots in your application that you don't even know are an issue.



Our blind spots about validation can and do harm real users if they're poorly or incompletely thought out. What might seem like a completely rational limit to us might hurt a real user who needs to exceed that limit, through no fault of their own. How many women are "BETTYJEAN" because their first name "can't" have a space in it?


He makes a few suggestions developers can do to help the situation and get their current project's validation back out into 20-20 vision:



  • Accept valid data in any form provided by the user.
  • Where possible, use well-developed validation libraries.
  • Do not place artificial limits on valid data.
  • Do place valid limits on specific data.

2011年4月1日星期五

Site News: Popular Posts for the Week of 04.01.2011

Popular posts from PHPDeveloper.org for the past week:

PHPCodeBase.com: PHP Magic Function : glob()


On PHPCodeBase.com there's a recent post looking at a handy file system function that you can use to search directories simpler than a usual opendir/readdir method - glob.



Are you guys still using opendir() function to read the the files from the folder in PHP? Luckily PHP have the glob() function which perform this task very faster and smarter.


He compares an example of the opendir/readdir method to a few line replacement with glob, both searching the same directory for files. He looks at the arguments you can pass into glob - the path to search and a flag that adds special handling to the method (like turning off sorting, modifying the regular expression handling and stopping on errors).

php|architect: php|architect Announces the First Annual Impact Awards


php|architect has announced a new effort they've launched to recognize the groups and projects in the PHP community that have had an impact. The Impact Awards is a yearly effort to recognize those contributions.



In short, we at php|architect recognize that we are standing on the shoulders of giants. We build our site, our training and our magazine using tools created by developers who are giving freely of themselves. We want to recognize a few of those who have had an impact specifically on the PHP community. The full details can be found on the Impact Awards page. Voting is open through the end of April to all php|architect subscribers. The winners will be announced at php|tek '11 in Chicago.


To vote, go over to the Impact Awards site and pick from their selections of people from categories like: the groups around various frameworks, integration/development, data management and up and coming projects. The winner will be presented with an actual award as designed by Toronto-based architect Alex Ilievski.

Eric Hogue's Blog: Profiling a PHP Application


Eric Hogue has written up a new post about a few different technologies you can use to profile your PHP applications quickly and easily.



There are many available tools to profile a PHP application. Learning how to use them can help us pinpoint which parts are slow. With this information we can pick the optimizations that will give us the best results. This post describes the installation and configuration of some of them. I tested them in a Ubuntu 10.10 virtual machine. If you want to try those tools, don't forget that they can greatly impact the performance of you web server when they are active. Installing a tool like Xdebug on a production server is not recommended.


First he looks at benchmarking your application with a tool called Siege, a load testing tool that can be configured to send requests to your application in lots of different ways. He also mentions Xdebug, a handy debugger and XProf, a profiling tool to help find the bottlenecks in your code (and XHGui to view its results).