- InfoWorld: Review: 2 PHP tools rise above the rest
- Monitor.us Blog: Website Performance: PHP
- Chris Morrell's Blog: Introducing Zit, an object-oriented dependency injection container
- James Fuller's Blog: Enforcing contracts in your PHP functions and methods
- Freek Lijten's Blog: SOLID - The S is for Single responsibility
- Alex Hudson's Blog: A (fond) farewell to Zend Framework
- PHPMaster.com: Continuous Integration (with Jenkins), Part 1
- Site News: Popular Posts for the Week of 03.23.2012
- Cats Who Code: Sending SMS with PHP and TextMagic: An A to Z guide
- Emran Hasan's Blog: Using Mockery as a mocking framework with PHPUnit
2012年3月30日星期五
Site News: Popular Posts for the Week of 03.30.2012
Rob Allen's Blog: Returning JSON using the Accept header in ZF2
In a previous post Rob Allen showed how to return JSON data from a controller in a Zend Framework 2 application. In this new post he shows how to use the "Accepts" header from the client to do the same thing.
Following yesterday's article on returning JSON from a ZF2 controller action, Lukas suggested that I should also demonstrate how to use the Accept header to get JSON. So this is how you do it!
You'll need to create the JsonStrategy first, then you can return the ViewModel from the controller. If all goes well, you should see the sample HTML page rendered in a browser and JSON output when requested with the right "Accept" header (he uses curl in his example).
DZone.com: How to Set up Wordpress on EC2 Using Puppet and Git
On DZone.com there's a new article from Daniel Ackerson showing how to set up a WordPress instance on an Amazon EC2 instance with the help of Puppet and git.
Having started out on a Joyent appliance, migrating to Linode, and finally, to Amazon with a Bitnami stack, we noticed the common pain of manually configuring each of these environments. Bitnami caused us an even bigger headache by being very difficult to update (apt-get doesn't update the bitnami wrapped AMP stack). We decided to get full control of our box by setting up a stock Debian LAMP stack on AWS using Puppet and git to manage our sites. Here's a gentle introduction on how we did it.
He guides you through the entire process:
- Setting up a micro instance on EC2
- Signing up for unfuddle (for git)
- Installing Puppet (standalone)
- Setting up your git repository to point to unfuddle
- The needed Puppet configuration files to get the WordPress instance deployed
Complete code (and commands) are provided in the post.
Lee Davis' Blog: FormFactory - Driving Doctrine 1.2 / 2.x Mappings into Zend_Form objects
Lee Davis has a recent post to his blog showing how you can combine the Zend_Form component of the Zend Framework with Doctrine to help directly "drive" your forms.
On a few of my previous projects I found myself creating more form classes than I'd like. And after the 30th one I figured there had to be a better way. I quickly realised that most of the elements within these forms shared similarities to the data type I would use on my database definitions. As I was using Doctrine at the time I figured I could not only drive my database from my mapping definitions, but my forms too.
He shows how his library (github) can be used to create a simple mapping between the form fields and the Doctrine entities, building from settings in an ini file. It also allows you to fall back to the normal Zend_Form configuration directives if you need something more custom. The post gets into more detail about using the project (configuring caching, other config options).
The project can be found here on github.
2012年3月29日星期四
Nikita Popov's Blog: Understanding PHP's internal array implementation (Part 4)
Nikita Popov has posted the fourth part of the "PHP's Source Code for PHP Developers" series he and Anthony Ferrara have been posting. In this latest article in the series, Nikita looks specifically at PHP's array implementation and how it's handed "behind the scenes".
Welcome back to the fourth part of the "PHP's Source Code for PHP Developers" series, in which we'll cover how PHP arrays are internally represented and used throughout the code base.
He starts with an obvious foundation: "everything's a hash table" (even properties, classes and yes, arrays). He describes what a hash table is and talks about two of the most commonly used versions of it in the PHP source - HashTable and Bucket. He gets into their usage a bit and compares this to the corresponding PHP code that uses a standard array.
Community News: Win a phpDay/jsDay 2012 Ticket
The jsDay/phpDay organizers have announced a contest to win a free ticket to this year's event(s), one for each conference:
GrUSP is organising a tweet contest and its prizes will be two tickets, one for each conference. The contest will start today (March 29th) at 1pm CEST and will end April 1st at 7pm CEST.
Anyone can enter - all you have to do is tweet a post with a few things: the "#grsup" hashtag, a mention of the twitter accounts for the events, a link to the conference site and something about the event. Be sure and get those tweets posted before April 1st a 9am CEST - they'll pick the winners soon after! (Oh and multiple entries are accepted so the more you tweet, the better your chances!)
2012年3月28日星期三
Chris Hartjes' Blog: Metatesting: Understanding Mock Objects
In this new post to his blog Chris Hartjes gets into some details about some complex mocking he recently had to do in a project for work. He includes code snippets to illustrate.
With such an extensive array of tests [at work], I have received an education in what it really means to write unit tests for live, production-ready code that really takes unit testing seriously. [...] If you are really writing your unit tests the way you should, each test is focusing on testing one bit of functionality in isolation, which means that you will be heavily relying on mock objects to make things work. I've come up with an example scenario that I hope goes a long way to explaining how to effectively use mock objects.
In his example, he shows how to mock out two objects, "Foo" and "Bar" that are passed into a method in his "Alpha" class. He looks at the code for the "Foo" class and creates a mock object based on its contents - two methods: "getId" and "getDetails". He does the same with the "Bar" class, mocking the "getStartDate" and "getEndDate" methods and showing how to pass those into the "munge" method on the "Alpha" class, complete with return values to match the tests.
For more information on PHPUnit's mock object support, see this page in its manual. You might also explore another popular option, Mockery.
Liip Blog: Table Inheritance with Doctrine
On the Liip blog there's a recent post looking at table inheritance with Doctrine, the popular PHP ORM tool. In the post, Daniel Barsotti talks about a database model that needed some updating due to their searching needs.
Our first idea, and it was not that bad, Drupal does just the same, was to have a database table with the common fields, a field containing the type of item (it's either an event or a blog post) and a data field where we serialized the corresponding PHP object. This approach was ok until we had to filter or search LabLog items based on fields that were contained in the serialized data.
To resolve the issue they turned to multiple table inheritance, relating the LabLogItem to both a BlogPost and Event. They also show how it could be modeled with a single table, but opt for the multiple method. Included in the post is the Doctrine-based code showing how to create the parent entity for the LabLogItem and the two child entities for the blog post and event. There's also a brief snippet showing how to use them with the EntityManager.
Lorna Mitchell's Blog: Using JIRA's REST API to Create a Dashboard
In this recent post to her blog, Lorna Mitchell shows how to use the Jira REST API (provided as a part of some of the newer versions of the tool) to create a "dashboard" of the latest items added to the tracker.
Today what you get is an example of integrating with JIRA's REST API, because their recent "upgrade" locked me out of the issue listings pages completely and I really do need to be able to see a list of bugs! Their bug editing screen is quite usable, so it's just the list that I need here, but you could easily call their other API methods as you need to. These examples are PHP and use the PECL_HTTP extension, because it's awesome, but these examples could be easily adapted to use another language or library.
She includes an example of the REST-based URL to fetch the issues (based on the Joind.in Jira tracker), parsing the JSON results and displaying the results as a simple list, looping with a foreach and outputting some HTML.
2012年3月27日星期二
Joshua Thijssen's Blog: PHPShout : a shoutcast streamer in PHP
Joshua Thijssen has a new series of posts to his blog about a new extension he's created for PHP that lets you stream music files to an IceCast server with only PHP.
To continue our journey in pointless, but nevertheless fun things to create, I've created a simple PHP extension that allows you stream music data to an IceCast server in pure PHP. For this I'm using the libshout3 library which can stream both MP3 or OGG/Vorbis data to multiple stream servers (including IceCast, ShoutCast etc). In this blog-post I will try to explain how I've created this extension, and off course, how you can use it.
The series is split up into four parts:
- Part 1 - download and install (and some behind the scenes)
- Part 2 - parts of the extension and a first test
- Part 3 - populating the store, adding getters
- Part 4 - creating setters and some other random functionality
You can find the source for this extension over on his gihub repository.
DZone.com: Including PHP libraries via Composer
On DZone.com there's a new post from Giorgio Sironi about using Composer to install packages/libraries:
The main package source used by Composer seems more similar to the usage of git submodules at a first glance: a list of dependencies on other projects is specified and stored under version control, and upon a checkout these projects are grabbed directly from their repositories.
He talks about what problem the project solves, what issues he's found with it so far (the amount of stuff downloaded for each dependency, the single point of failure of the one Packagist repository) and shows how to get it installed and creating a sample "composer.json" file for an example project.
Cats Who Code: Sending SMS with PHP and TextMagic: An A to Z guide
On the Cats Who Code site today there's a new tutorial showing how to send SMS messages from your PHP application with the help of the TextMagic service.
Over the years, Short message service (SMS) has become a very important way of communication, and many businesses are looking for easy ways to send automated text messages to their customers. In this tutorial, I'm going to show you how you can send SMS using PHP and a third party service called TextMagic. Its very easy to do!
They step you through the process - creating a TextMagic account, configuring the account with your own password and creating a simple script that includes their own API library and sends the SMS request.
PHPMaster.com: How I Faked Scheduled Database Dumps Without Cron
On PHPMaster.com today there's a new tutorial about a way to simulate cron jobs to dump the contents of a database with a simple script that fires off based on the last login time of a certain user (using the MySqlDumper tool).
My program required a accurate username and password to present its features to the user, and there is one predefined user who is idle most of the time and does just two things: wipe stale database entries and restore the database when needed. According to my login procedure, each time a user successfully logs in the system automatically updates the last login date to the current date. And that was the hint I desperately needed.
A brief snippet of code is included showing how he implemented the solution - MySQL commands and parameters defined in constants and called only when the last login time is less than "today".
2012年3月26日星期一
Alex Hudson's Blog: A (fond) farewell to Zend Framework
In this most recent post to his blog Alex Hudson says a "fond goodbye" to using the Zend Framework for his applications after trying out some of the functionality that's in Zend Framework version 2:
I've been a Zend Framework user for a while. I've been using PHP long enough to appreciate the benefits of a good framework, and developed a number of sophisticated applications using ZF, to have grown a certain fondness for it. [...] That said, I actually don't feel like much of what I'm about to say is unfair, for one simple reason: I have tried to like ZF 2.0. [...] I got quite happy with ZF1, and indeed approached ZF2 with the idea that it would take a similar amount of effort to learn to like it. I have attempted to apply that effort. I have failed.
He goes on to talk about some of the things that he found that he doesn't like about this upcoming version of the framework, including:
- the lack of an interesting demo to show off what ZF2 can really do
- the almost "koolaid" approach ZF2 approaches dependency injection with
- some references to "Java mentality" that seems to be creeping into the framework
NetTuts.com: Create Instagram Filters With PHP
On NetTuts.com there's a new tutorial showing how you can create Instagram-like filters in PHP using the ImageMagick library/extension.
PHP comes bundled with GD (GIF Draw/Graphics Draw), which is a library for the dynamic creation of images. It can be used for simpler image operation, such as resizing, cropping, adding watermarks, creating thumbnails (Jeffrey wrote about it), applying basic photo filters - you've probably used it before. Unfortunately, if you want to create something more complex with GD, like Instagram effects, you can't. Luckily, though, we have ImageMagick!
He starts off by comparing the two graphics libraries and talks briefly about how to downliad and install Imagemagick on your development platform. Included is a PHP class to help you use it, coming complete with functions for changing the color tone of the image, adding a border and adding a vignette to the image. Also included are some "presets" represented in a few simple functions:
- Gotham
- Toaster
- Nashville
- Lomo
- Kelvin
There's also a few links to other resources you can use to find out more details on what Imagemagick has to offer.
2012年3月23日星期五
Site News: Popular Posts for the Week of 03.23.2012
- Community News: phpDocumentor Merges with DocBlox for phpDocumentor 2!
- Brandon Savage's Blog: "PHP Playbook" Giveaway!
- Ryan Mauger's Blog: Controller Testing with the FlashMessenger in Zend Framework
- Rob Allen's Blog: A list of ZF2 Events
- PHPMaster.com: Building a Domain Model - Integrating Data Mappers
- Pascal Opitz's Blog: An example of how to use Pimple DI with ZF 1.x
- Nikita Popov's Blog: Understanding PHP's internal function definitions (Part 2)
- Phillip Norton's Blog: Getting Started With PHP DocBlox
- Paul Jones' Blog: Interview Tip: Avoid Mentioning PHP Frameworks
- Brandon Savage's Blog: REST APIs as Data Backends
James Fuller's Blog: Enforcing contracts in your PHP functions and methods
James Fuller has a new post to his blog today about a way you can enforce contracts in your PHP using a combination of type hinting and value checking.
Design by contract is an important concept for controlling what type of input your methods or functions can receive. One of the most dangerous features of PHP is that functions will still execute even when they are missing required arguments, by emitting a warning instead of an error. In this post, I am going to walk through some of the solutions available to deal with this problem.
He shows how to alter a basic function to first use type hinting to catch when a variable is the wrong type (in this case checking for an array and stdClass) which causes a Fatal error and makes the function not execute. He includes sample code for the type/value checking option and also includes a suggestion of using PHPUnit's assertions as another option.
Finally, he introduces the ContractLib tool (from Stuart Herbert) that makes use of closures to enforce checks - his example checks to see if something is a string and that it's not empty.
Monitor.us Blog: Website Performance: PHP
On the Monitor.us blog there's a recent guide to performance tuning your PHP with sections on lots of topics, some related directly to the code and others more towards the environment it lives in.
The World-Wide Web offers more PHP performance tips than can be comfortably discussed in one article, so the following is merely a list that can be used for reference purposes. The tips are divided into categories to group similar things together and make it easier to find what we need. The author's search for tips was extensive, but completeness still cannot be guaranteed.These tips fall into category #3.1 (the server executes a script) in the taxonomy of tips that we have been working with.Because of the sheer volume, these tips have not been tested. The reader is expected to test them in his own production environment before relying on them. This is not unreasonable, though, because the value of most tips depends on the unique environment within which PHP operates.
Sections in the guide include:
Also included in the post are a list of links that were references for the tips in the list..
InfoWorld: Review: 2 PHP tools rise above the rest
InfoWorld has a new article posted looking at some of the PHP IDE options out there and comparing some of their strengths and weaknesses including PHPStorm, Eclipse, Aptana and Zend Studio.
PHP is more than just a language for junior high school kids to learn after they master balancing DIV tags in HTML. It can support enterprise-grade installations and deliver the kind of heavy lifting that brings power plants to their knees. [...] To get a flavor for the latest in PHP programming, I spent some time unpacking the current set of development tools for PHP - eight in all.
The IDEs he sampled were:
- Zend Studio
- PHPStorm
- PhpEd
- phpDesigner
- NetBeans
- Komodo IDE
- CodeLobster
- Aptana Studio
He points out that, while all of these tools have their good and bad things about them, sometimes you don't need something that heavy to get the job done. Sometimes something simpler might do just right. He recommends trying them out on your projects and seeing which is the best fit, though. He thinks that you'd probably "need to be working on a bigger PHP project" before an IDE would become really useful though.
2012年3月22日星期四
Site News: Blast from the Past - One Year Ago in PHP
- PHP.net: Security Notice (wiki.php.net)
- Sean Coates' Blog: PHP Community Conference
- Phil Sturgeon's Blog: Video: Set up a REST API with CodeIgniter
- Propel Blog: The End of Autoloading
- Slawek's Blog: Efficient file serving in PHP application with nginx
- Kevin Schroeder's Blog: Integrating Zend_View with WordPress
- Volker Dusch's Blog: Mandatory "Template Engines (Twig) vs Plain Old PHP" Post
- Rob Allen's' Blog: A Zend Framwork compound form element for dates
- Stoyan Stefanov's Blog: JavaScript-style object literals in PHP
- Chris Jones' Blog: Building PHP 5.3 with Oracle HTTP Server 11g
- Sameer Borate's Blog: Easy thumbnail generation using PHP
- Saltwater.eu: PHP Cloud Management: Orchestra vs. PHP Fog
- Matthew Weier O'Phinney's Blog: Dependency Injection: An analogy
- Stuart Herbert's Blog: Introducing phix
- Sebastian Bergmann's Blog: Debugging with Git and PHPUnit
Anthony Ferrara's Blog: PHP's Source Code For PHP Developers - Part 3 - Variables
The third part of the "PHP source for developers" series has been posted over on Anthony Ferrara's blog today looking at the variables PHP's internals use.
In this third post of the PHP's Source Code for PHP Developers series, we're going to expand on the prior posts to help understand how PHP works internally. In the first post of the series, we looked at how to view PHP's source code, how it's structured as well as some basic C pointers for PHP developers. The second post introduced functions into the mix. This time around, we're going to dive into one of the most useful structures in PHP: variables.
He starts with one of the most important variable types used in PHP's source - the ZVAL. This is one of the keys to PHP's loose typing and can be thought of as "a class with only public properties". He gets into more detail with the properties of this "class" (value, refcount__gc, type and is_ref__gc). Also included is a look at how it's actually used - creating new ones, getting the value of them, converting their types and how the internal PHP functions parse their variables.
There's a lot more covered about variables in the post so if this is interesting stuff to you, be sure to read it all. They've done a great job of explaining one of the more complicated parts of the internals that power PHP.
Johannes Schlüter's Blog: Testing persistent connection and thread-safety features in PHP
In this recent post to his blog Johannes Schlüter he talks about a way that he's come up with to test functionality that uses persistent connections (and an module he created to help).
In a few rare cases this is not what people like, for that PHP introduced "persistent connections" of different kinds. Testing those is a bit annoying as you have to configure a webserver and ensure to hit the same instance over the course of a test and then use a load generator, probably one which can detect a failure. Additionally by having a webserver in the game there is more code being executed, which might mean an additional source for trouble while debugging. An alternative might be using FastCGI, while that adds it's own issues for such a test. To solve this for myself I, some time ago, wrote a PHP SAPI module called pconn and pushed it to github.
The extension provides a way to emulate requests by executing a script multiple times automatically, making it easier to test things that require checking against multiple things simultaneously. While the built-in webserver (PHP 5.4) can be used to test some of these things too, Johannes' extension can also be compiled to help with testing of threading in applications as well.
Community News: PHPNW April Meetup - Derick Rethans on MongoDB Schemas
The PHP North West user group has announced their latest meetup happening April 3rd at 7pm in Manchester. Derick Rethans will be speaking about designing MongoDB schemas.
One of the challenges that comes with moving to MongoDB is figuring how to best model your data. While most developers have internalized the rules of thumb for designing schemas for RDBMSs, these rules don't always apply to MongoDB. The simple fact that documents can represent rich, schema-free data structures means that we have a lot of viable alternatives to the standard, normalized, relational model. Not only that, MongoDB has several unique features, such as atomic updates and indexed array keys, that greatly influence the kinds of schemas that make sense.
For more information, check out their event page, complete with details about the venue and maps to the location.
Have a user group meeting coming up you'd like to announce? let us know!
PHPMaster.com: Error Logging with MongoDB and Analog
On PHPMaster.com today there's a new tutorial from Lorna Mitchell introducing you to using Analog for error logging in a MongoDb connection. Because of the way the tool (Analog) is designed, it could be used anywhere - she just uses the MongoDB connection as an example because it integrates easily and efficiently.
MongoDB is an excellent fit for logging (and of course other things as well) for many reasons. For one, it is very VERY fast for writing data. It can perform writes asynchronously; your application wont hang because your logging routines are blocked. This allows you to centralize your logs which makes it easier to querying against them to find issues. Also, its query interface is easy to work with and is very flexible. You can query against any of the field names or perform aggregate functions either with map/reduce or MongoDB 2.2's upcoming aggregation framework.
This article will show how you can use existing code to add a logging library to your code and log errors to MongoDB. You'll also see how to query MongoDB from the command line and how to filter those queries to find the information you are interested in.
Analog makes it simple to log information in an easy to use, self-contained, extensible kind of way, offering writers for multiple output formats including: files, the FirePHP plugin output, email, POSTing to another machine and sending to a syslog daemon. She also mentions the different logging levels the tool makes available and how to filter down your logging results based on them (searched by "equal to", "greater than" and grouped by level).
2012年3月21日星期三
Community News: phpDay & jsDay Announce First Speakers!
The phpDay/jsDay conference organizers have passed along an update about this year's conference(s) (happening May 167th/17th & 18th/19th in Verona, Italy) - they've confirmed some of their first speakers for both sides of the event!
We are very happy to announce the first confirmed speakers for the
jsDay and phpDay 2012!
jsDay: Mark Boas (jPlayer/Happyworm), Greg Schechter
(YouTube),Christopher Rhodes (Google) and Brandon Keepers (GitHub) ,
the full list here.
phpDay: Rasmus Lerdorf (Php creator), Zeev Suraski (CTO at Zend,
Co-architect of PHP), Lorna Jane Mitchell (PhpWomen) and David
Coallier (Orchestra CTO) and many other, the full talk list here.
Their Early Bird tickets are on sale until April 1st for both of these two-day events, so be sure you pick up your tickets now before this great discount expires! (jsDay tickets, phpDay tickets)
Community News: PHP-GTK Migrates to Git/Github
As a part of the move to git/github that the PHP project recently made, a reminder was posted that the PHP-GTK project has also migrated.
PHP-GTK is a PHP extension that enables you to write client-side cross-platform
GUI applications. This is the first such extension of this kind and one of the
goals behind it was to prove that PHP is a capable general-purpose scripting
language that is suited for more than just Web applications.
The full source can be found and forked/cloned over on github and is just waiting for you to contribute!
DZone.com: PHP objects in MongoDB with Doctrine
On DZone.com today Giorgio Sironi has a new post showing how you can use Doctrine with MongoDB to work with Document objects from the database.
In the PHP world, probably the Doctrine ODM for MongoDB is the most successful. This followes to the opularity of Mongo, which is a transitional product between SQL and NoSQL, still based on some relational concepts like queries. [...] The case for an ODM over a plain Mongo connection object is easy to make: you will still be able to use objects with proper encapsulation (like private fields and associations) and behavior (many methods) instead of extracting just a JSON package from your database.
He briefly mentions that the PECL extension for Mongo needs to be installed prior to trying out any of the examples. His first example shows how to create a DocumentManager (similar to the normal EntityManager for those familiar with Doctrine). He also shows an integration with the ORM and shares some of the findings he's made when it comes to versioning the resources (hint: annotations are your friend).
Brandon Savage's Blog: Rocking Your Job Interview
Brandon Savage has a new post to his blog with a few tips about doing well ("rocking") in your next job interview.
One of the things about the PHP field is that developers are highly sought after, and good developers are prized. While anyone can slap "PHP Developer" on their resume, most companies have gotten good at weeding out the pretenders from the real deal. This means that for a highly qualified developer, interviewing should be an easy step towards receiving an offer.
He's broken it up into a few different main points:
- Know your technical details thoroughly.
- Know the role of the person interviewing you.
- Be able to turn technical answers into non-technical answers, and vice versa.
- Learn how to be personable.
- Ask thought-provoking questions.
Each point comes with some thoughts on how to accomplish it and even points to two resources to help you on your way.
2012年3月20日星期二
Brian Swan's Blog: Azure Real World: Migrating a Drupal Site from LAMP to Windows Azure
In this new post to his blog Brian Swan shares the process that he and other Microsoft-ers went through to migrate a site off of a LAMP stack and over to one based on Windows Azure. They moved was the SAG awards website because of issues it had seen with outages and slow performance.
In many ways, the SAG Awards website was a perfect candidate for Windows Azure. The website has moderate traffic throughout most of the year, but has a sustained traffic spike shortly before, during, and after the awards show in January. [...] The main challenge that SAG Awards and Microsoft engineers faced in moving the SAG Awards website to Windows Azure was in architecting for a very high, sustained traffic spike while accommodating the need of SAG Awards administrators to frequently update media files during the awards show. Both intelligent use of Windows Azure Blob Storage and a custom module for invalidating cached pages when content was updated were key to delivering a positive user experience.
He walks you through each of the five steps (high-level, obviously) that they took in the migration:
- Export data
- Install Drupal on Windows
- Import data into SQL Azure
- Copy media files to Azure Blob Storage
- Package and Deploy Durpal
Each step comes with some explanation and descriptions of the commands and tools used during the process.
Paul Jones' Blog: Interview Tip: Avoid Mentioning PHP Frameworks
Paul Jones has offered a tip he thinks will help you in future interviews for a software development position - don't mention frameworks.
If the job description does not mention "Framework X," you should probably avoid answering that you use "Framework X" to solve the problem presented to you by the interviewer. If I ask you to perform a simple task, such as parsing a string in a well-known format, saying "Framework X does that for me" is likely to be seen as a negative. You should be able to do the simple things in PHP itself (e.g. parsing strings).
He points out that, as someone currently in the interview process, he is frustrated by the fact that some developers rely so heavily on the functionality that frameworks give them that they don't know how to do some of the most basic tasks outside of them.
Saying that you use a feature of "Framework X" for simple things is a negative. It sounds like you're dependent on that framework for basic tasks. That means we (the employers) will need to train you how to do it without that framework, and that's a hassle for us.
Project: RIPS - Static Source Code Analyzer for Vulnerabilities in PHP Scripts
Gareth Heyes has pointed out an interesting tool today for analyzing the source of your application and trying to discover security-related issues: RIPS
RIPS is a tool written in PHP to find vulnerabilities in PHP applications using static code analysis. By tokenizing and parsing all source code files RIPS is able to transform PHP source code into a program model and to detect sensitive sinks (potentially vulnerable functions) that can be tainted by userinput (influenced by a malicious user) during the program flow. Besides the structured output of found vulnerabilities RIPS also offers an integrated code audit framework for further manual analysis.
The project site lists out the features that come with the tool, what it searches for (including command execution issues, header injection, file manipulation and SQL injection) and some example screenshots of its interface. You can download the latest version and try it out for yourself.
Voices of the ElePHPant Podcast: Interview with Jacques Woodcock (of Nashville PHP)
The Voices of the ElePHPant podcast has posted their latest episode - an interview with Jacques Woodcock, a leader in the Nashville PHP community (including the Nashville PHP user group) and developer on The Kit.
Cal's "three questions" for Jacques are:
- What made you choose PHP (despite not having a background in programming)?
- What have you learned about the PHP community that you didn't know before starting with the user group?
- What's been the most interesting part of leading the Nashville PHP user group?
You can listen to this latest episode either via the in-page player or by downloading the mo3 directly. You can also subscribe to their feed to get this and other great episodes automatically.
2012年3月19日星期一
Nikita Popov's Blog: Understanding PHP's internal function definitions (Part 2)
Following this recent post from Anthony Ferraara about the source code of the PHP language itself, Nikita Popov is working with him and has produced the second part of the series, a look at finding the internal function definitions for the PHP functions you use every day.
In the previous part ircmaxell explained where you can find the PHP source code and how it is basically structured and also gave a small introduction to C (as that's the language PHP is written in). If you missed that post, you probably should read it before starting with this one. What we'll cover in this article is locating the definitions of internal functions in the PHP codebase, as well as understanding them.
He starts with a basic example - a string function, strpos. He shows a handy searching trick to help find the actual function definition and which matches should be given priority. He lays out a typical skeleton of a PHP function definition and gets into some detail as to what this particular function does (in C). He briefly mentions the Zend Engine functions and a look ahead to finding classes and methods.
Brandon Savage's Blog: REST APIs as Data Backends
In his most recent post Brandon Savage looks at a practice that's becoming more and more common - using a REST API as a data source for a web-based application.
We were faced with an increasing number of data sources, including the coming addition of Elastic Search to the data storage system, and maintenance was becoming a problem. Thus, the decision was made to move our data layer to our REST API exclusively, removing all direct access to data storage from the web interface. This is the second such project I've been on where an external API has been used for the retrieval of all data in an application. It's a novel concept, but one that takes some getting used to to be sure.
He talks about some of the advantages of this approach including the ability to be more flexible with the actual technology used to create the API, the ability to write other applications on top of it and a glimpse into some of the process that's been going on as a part of the project.
Henri Bergius' Blog: Open Advice (Book)
If you're into Open Source software (doesn't matter if you're new to it or an old hand), you'd do well to check out the book Henri Bergius has posted about - that he also contributed to - "Open Advice - FOSS: What We Wish We Had Known When We Started".
As quoted from the LWN review of the book:
Open Advice is a book that will be helpful to those who are new to FOSS, but, because of the individual voices, styles, and tones, it doesn't read like a "how to". It could even be recommended to those who aren't necessarily interested in contributing, but are curious about what this "free software thing" is all about.
It contains real experience from real developers that work on FOSS projects with chapters titled:
- "Code First"
- "University and Community"
- "Love the Unknown"
- "Quality Assurance"
- "Good Manners Matter"
- "Stop Worrying and Love the Crowd"
The book is licensed under a Creative Commons license (CC-BY-SA) and can be downloaded in multiple formats - ePub, mobi, PDF and paperback, if you prefer that.
2012年3月16日星期五
Site News: Popular Posts for the Week of 03.16.2012
- Anthony Ferrara's Blog: Handling Plugins In PHP
- Pádraic Brady's Blog: XSS in PHP (Part 1): How Not to Use Htmlspecialchars
- Kevin Schroeder's Blog: My first stab at the Dependency Injection Container in Zend Framework 2
- Smashing Magazine: Writing Unit Tests For WordPress Plugins
- Hari KT's Blog: Is there a design flaw for the Components or Packages made by Symfony2 and ZF2
- Ralph Schindler's Blog: PHP Constructor Best Practices And The Prototype Pattern
- PHPMaster.com: Role Based Access Control in PHP
- Daniel Krook's Blog: Migrating PHP applications to DB2
- PHPMaster.com: Form Validation with PHP
- Freek Lijten's Blog: Book Review - Growing Object-oriented software guided by tests
Community News: phpDocumentor Merges with DocBlox for phpDocumentor 2!
As is mentioned in this new post to the DocBlox blog, there's been a major development between it and the phpDocumentor documentation generation tool - phpDocumentor 2 will be released soon, merging DocBlock and phpDocumentor into one tool!
Announcing phpDocumentor 2 - the merging of the old (phpDocumentor) and the new (DocBlox). With the first alpha release of phpDocumentor (2.0.0a1), the new "Responsive" default template sports a new page layout, along with the useful layout improvements that the original DocBlox templates provided (which remain available) over the old phpDocumentor templates (which will retire with old phpDocumentor). Explore this new template at http://demo.phpdoc.org/Responsive/index.html.
Users of the current phpDocumentor software (version 1.x) will need to upgrade their documentation and installations. If you'd like more information about the transition or just keep up with the latest on this exciting advancement, check out #phpdocumentor on Freenode IRC or follow @phpdocumentor on Twitter.
Pascal Opitz's Blog: An example of how to use Pimple DI with ZF 1.x
Pascal Opitz has a really quick post to his blog showing a snippet of code about using Pimple with the Zend Framework 1.
After having had a look at Silex, and struggling with the somewhat cumbersome ini configurations and YADIF, I wanted to try out whether I could use Pimple as DI container for ZF 1.x Turns out I can, as you can just select Pimple to be the bootstrap container.
Hsi example (gist of the code here) also shows how to subclass the container and add in some default settings objects into the container. Pimple is a small, lightweight dependency injection container from Fabien Potencier of the Symfony framework.
Rob Allen's Blog: A list of ZF2 Events
In a reference sort of post, Rob Allen has listed out the events that are provided in the Zend Framework 2 "Application" functionality.
Both the Module Manager and the MVC system use the Event Manger extensively in order to provide "hook points" for you to add your own code into the application flow. This is a list of the events triggered by each class during a standard request with the Skeleton Application.
It's broken up into the three main chunks - Module Manager, Bootstrap and Application - with any sub-requests and their sources (like "render", "dispatch" or "response"). You can find out more about ZF2's Event Manager in other posts like this one from Kevin Schroeder or this from Matthew Weier O'Phinney.
Brandon Savage's Blog: "PHP Playbook" Giveaway!
In this new post to his blog Brandon Savage mentions his book, the PHP Playbook (php|architect), and how he's giving away several free copies.
When I started writing my book, I wanted to help PHP developers have a greater understanding of the tools, tips and tricks available when working as part of a team. That goal became The PHP Playbook. I'm excited that the book has been so well received, and I'm excited that I've finally received my promotional copies. So, in honor of that, I'm going to give some of them away! I'm even going to sign them!
Just enter in your email address and you'll be put on a mailing list for the book and its future updates. Here's the official description of the book:
Working with a team of developers is a much different environment than solo development. Experienced developers understand the tools and tricks that go into team development enterprises, and they implement them on a daily basis. The PHP Playbook covers these tools and practices, providing insight into the process of developing PHP applications, teaching developers the skills they need to be successful in a team environment.
2012年3月15日星期四
Site News: Blast from the Past - One Year Ago in PHP
- NetTuts.com: The ABCs of Web Development
- Rob Allen's Blog: Zend Framework View Helpers
- Chad Lung's Blog: A quick intro to using PHP PDO with MySQL
- Community News: "Ideas of March" Kicks off a "Blogging Revival"
- Kenny Katzgrau's Blog: Video: How GetSparks.org Uses CodeIgniter Sparks
- 9Lessons: Payment System with Paypal
- Freeaqingme's Blog: PHP, JS & Service layers: Blend like never before
- Gonzalo Ayuso's Blog: Real time notifications with PHP
- SearchCo.de: List of Most Commonly Used PHP Functions
- PHP.net: PHP 5.3.6 Released!
- FuelPHP: Oil Migrations, Tasks and Console (Screencast)
- Query7.com: A Look At PHP 5.3 Frameworks - Symfony2
- IBM developerWorks: Create a PHP development environment on the cloud
- Web Builder Zone: Which PHP framework would you use today for a brand new application?
- PHPFog Blog: Scaling PHP Up, Out, and Around
Volker Dusch's Blog: The UNIT in unit testing
Volker Dusch has a new post reminding us about what the "unit" part of "unit testing" means - small chunks of testable parts in an application.
What does the word UNIT in unit testing stand for? Think of an answer and read on! So? Did you say "A method! Because we test methods!"? If so let me offer another perspective.
He suggests that, rather than about just the methods in the class, it's more about testing the "observable behaviors" of the class. That is, anything that you could publicly use the class for and have something happen. He gives examples of this shift in focus - calling setValue and evaluating the result versus just calling the class property itself (then calling the method). He also includes a bit about testing behaviors - what happens when my script does [this] and how does that effect the overall class.
When your tests fail but the class "still works" and you need to "fix the tests" the your tests are worth a lot less as they don't really give you that cozy safety net that they should provide you with.
Community News: "Ideas of March" Blogging Refresh
This time last year, several members of the PHP (and wider) community wrote up blog posts titled "The Ideas of March". The idea was to blog about blogging and try to kickstart others and encourage them to get back on to blogging again. Here's a list of the people who have posted so far:
- Wez Furlong
- Lorna Mitchell
- Cal Evans
- Chris Cornutt
- Tom Mairs
- Jason Lotito
- Drew McLellan
- Sean Coates
- Chris Shiflett
- Joshua Thijssen
- Kevin Bruce
- Cameron Moll
This list will be updated throughout the day as more posts show up. Have a post you don't see mentioned here? Let me know!
Joseph Scott's Blog: Why PHP Strings Equal Zero
Joseph Scott has a new post to his blog looking at "why PHP strings equal zero" - that when you use the "==" operator on a string to compare to zero, it's true.
The issue of PHP strings equaling zero has come up a few times recently. [...] Running that will display Equals zero!, which at first glance probably doesn't make much sense. So what is going on here?
He gets into the specifics of what's happening - a bit of type jugging, less strict comparison since it's the "==" versus "===" and how the PHP manual talks about strings being converted to numbers.
While I still think it is odd that the string gets cast as an integer instead of the other way around, I don't think this is a big deal. I can't recall a single time where I've ever run into this issue in a PHP app. I've only seen it come up in contrived examples like the ones above.
Reddit.com: Let's talk Character Encoding
On Reddit.com there's a recent post with a growing discussion about character encodings in PHP applications (with some various recommendations).
I would rather not have to convert these weird characters to the HTML character entities, if possible. I'd rather be able to use these characters directly on the web page. If this is for some reason a bad idea, let me know. This might be more of a general web design question (i already posted it there), but I figured it is still appropriate to post here as well since PHP is used to pull an entry from the database, and I figured a lot of you here would know the answer to the question.
The general consensus is to use UTF8 in this case, but there's a few reminders for the poster too:
- Don't forget to make the database UTF8 too
- Be sure you're sending the right Content-Type for the UTF8 data
- an link to an article about what "developers must know about unicode/charactersets"
2012年3月14日星期三
Nefarious Designs Blog: Vagrant Virtualised Dev Environments
On the Nefarious Designs blog there's a (very complete) guide to Vagrant and using it to set up easily reproducible versions of your development environment.
In case you've been living under a rock for the past couple of years, Vagrant is the latest development in easily controlled virtualised environments. [...] Vagrant automates creation and provisioning of virtual machines within VirtualBox via the command line, whilst also allowing for easy distribution and reuse across multiple projects. In this article, I'm going to look at how it can make life considerably easier when dealing with development environments.
Included in the post is just about everything you'll need to get started using this powerful tool:
- A link to Vagrant images
- A guide to the VagrantFile
- the Provisioning process
- Interacting/Controllig the Vagrant VMs
He also includes a basic setup of an environment (with the Vagrant config to create it) and an example of using Puppet to provision the Vagrant VMs.
CodeIgniter.com: A Quick Look at Sparks
On CodeIgniter.com there's a new post looking at Sparks, reusable code components/packages for the CodeIgniter framework.
On the back of a CIConf in London last month, I would like to delve a little into a common theme amongst CodeIgniter developers. Speeding up development through simple automation. To do that we're going to take a look at the CodeIgniter Sparks project and how it can drastically speed up your development. To demonstrate, I will walk through building a little portfolio that leeches off the GitHub API.
They show you how to install it from the Getsparks website, finding Sparks to add to your application, the code to load in the component and configuring it on load. They include an example of loading in a REST client Spark and how to use it to make a request to Github and pull down a Markdown file.
NetTuts.com: Easy Form Generation Using FuelPHP
On the NetTuts.com site today there's a new tutorial from Sahan Lakshitha about creating forms in FuelPHP, the PHP 5.3-centric framework.
Thanks to FuelPHP's fieldset class, working with forms couldn't be easier. With a few lines of code, you can easily generate and validate a form. Today, we're going to learn how to do just that!
He starts with guiding you through a simple install of the FuelPHP framework and configuring it to connect to a MySQL database. He shows how to set up a model, specify its properties and creating a controller to handle the user interaction. Using the definitions in the model, FuelPHP can automatically generate a form, complete with default options and some validation on the field (things like "required", "valid_url" and "max_length"). There's also code included showing how to edit current posts and listing out the complete post list.
Community News: CICONF in San Francisco (August 2012)
The CICONF, the CodeIgniter conference, had a great success with it's UK event and now it's coming back to the US in August to San Francisco.
Following on from the success of our recent event in London last month we're happy to announce that the CodeIgniter Conference is back for more CodeIgniter-based antics! This time we'll be in San Francisco! We've got a new site, a new set of wonderful sponsors and early bird tickets will be ready shortly for those of you know just can't wait to reserve your place. Last time we very nearly sold out of tickets, so keep an eye out for them.
The event, happening August 11th and 12th will be at the Fort Mason Center in San Francisco. If you'd like to get involved (or maybe even speak!) let them know by entering your address on the main site or mentioning it on Twitter. You can pick up your Early Bird tickets now, though - a Student rate for $65 USD and a Full price for $95 USD.
2012年3月13日星期二
Gonzalo Ayuso's Blog: How to use eval() without using eval() in PHP
In this new post Gonzalo Ayuso talks about "using eval without using eval" in PHP applications - executing PHP code without having to use the eval function to do it.
Yes I know. Eval() is evil. If our answer is to use eval() function, we are probably asking the wrong question. When we see an eval() function all our coding smell's red lights start flashing inside our mind. Definitely it's a bad practice. But last week I was thinking about it. How can I eval raw PHP code without using the eval function, and I will show you my outcomes.
He includes some sample code showing a basic script with a class and a loop executing normally, then an "eval version" that puts it all in a string and executes it. He offers a different method - not an ideal one since it requires being able to write to the local file system, but prevents the need for eval - writing the PHP code to a temporary file and using a "fake eval" to pull it in.
2012年3月12日星期一
Michael Nitschinger's Blog: Getting Started with Couchbase and PHP
In his most recent blog post Michael Nitschinger introduces you to Couchbase, a document-oriented database, and how to use it with PHP.
As there were a lot of merges, renamings and releases, it was pretty hard to follow up with the current/best database version and SDK to use for your project. Now as the dust has settled a bit, here's what I've come up with: Couchbase 2.0 will be the next major version and is already pretty stable, so I'll jump straight onto it and skip 1.8.
He recommends using the php-couchbase libraries or the php-ext-couchbase extension. He walks you through the whole process of getting Couchbase installed and running and the PHP support installed via the aptitude package manager. A sample script and some basic usage information is also included.
Chris Hartjes' Blog: Moving on, and a Testing Mini-Manifesto
As a part of moving on to a new job and a shift in perspectives, Chris Hartjes has decided to write up a manifesto about testing, a big focus in his development life:
With the new position comes more of the stuff I am really passionate about: testing and automation. Which also got me to thinking about the reasons why I am so passionate about these things. I thought I would create my own little testing mini-manifesto here. The ideas my podcasting partner did with his MicroPHP Manifesto made me realize that sometimes it is good to write these things down, as it were.
His manifesto incudes a set of basic (yet fundamental) ideas about application testing:
- I test because the tools are easy to use
- I test because I don't like surprises
- I test because I want people to understand what I've done
- I test because I want to be able to change things fearlessly
- I test because automation is a secret weapon
- I test because it forces me to focus on design
- I test because to me it is the right thing to do
Rob Allen's Blog: Some ZendView examples
Following on the heels of the beta 3 release of the Zend Framework 2, Rob Allen has been posting more about its features and what's changed from the version 1 world. In this new post he looks at some examples of how to use the newly refactored ZendView component.
With the release of Beta 3 of Zend Framework, we now have a significantly refactored the ZendView component. One of the changes made is that there is a ViewModel object that is returned from a controller which contains the variables to be used within the view script along with meta information such as the view script to render. [...] However, we can do many more interesting things than this and I've put together a test application with a controller showing some of the things that can be done.
Included in the post includes two snippets of code from the sample project - how to change the layout in the action and creating another view model at the layout level.
2012年3月9日星期五
Site News: Popular Posts for the Week of 03.09.2012
- Project: phpVirtualBox - VirtualBox Management Tool
- Jeremy Cook's Blog: Making PHPUnit, Doctrine & MySQL Play Nicely
- Zend.com: Zend Framework 2.0 Beta 3 Release Gives Developers an Early Start
- Sebastian Marek's Blog: PHP 5.4 Compatibility Coding Standard for PHP_CodeSniffer
- Slawek Lukasiewicz's Blog: New Features in PHP 5.4 - JSON Extension & header_register_callback
- PHPMaster.com: Type Hinting in PHP
- Bas De Nooijer's Blog: Benchmarking PHP Solr response data handling
- Rob Allen's Blog: Modules in ZF2
- Anthony Ferrara's Blog: Parameter Type Casting in PHP
- Josh Adell's Blog: GetSet Methods vs. Public Properties
Daniel Krook's Blog: Migrating PHP applications to DB2
As Daniel Krook mentions in his latest blog post, the IBM developerWorks site has just posted the last part of a series he's been writing about migrating a PHP application's backend over to DB2.
IBM developerWorks has just published the final part in our series on migrating a PHP application from MySQL to DB2. [...] In addition to sharing our own experience, the series highlights the number of resources available to you to carry out your own migration.
The series is broken up into four parts:
Hari KT's Blog: Is there a design flaw for the Components or Packages made by Symfony2 and ZF2
Hari K T has a new post to his blog that shares his concern about a "design flaw" in the component/package methods promoted by Symfony2 and Zend Framework 2:
Looking from outside both Symfony2 and ZF2 is full of standalone components. But the reality is not the same. Though Symfony2 components are split into each components in github, you cannot give a pull request to that component. The tests for all the components still resides in the core.
He points to the Aura framework project as a good example of how to make a truly component-centric set of tools complete with tests bundled into the component's download right next to the source.
2012年3月8日星期四
Site News: Blast from the Past - One Year Ago in PHP
- Dan Horrigan's Blog: Security in FuelPHP
- Steve Francia's Blog: Getting Started with Symfony2
- Ole Markus' Blog: Catching fatal errors in PHP
- David Behler's Blog: Dev-Box: Virtual Machines for Developers
- Stoyan Stefanov's Blog: Automating HTTPWatch with PHP
- WebDevHub: Scheduling emails in PHP
- php|architect: More powerful Validation from Respect
- PHPBuilder.com: Creating and Manipulating PDFs with PHP and FPDF
- Webification.com: Roundup of 17 Best PHP Template Engines
- Christian Schaefer's Blog: Simply iterate over XML with plain PHP using little memory and CPU
- Lorna Mitchell's Blog: Github to Jira Bug Migration Script
- Marco Tabini's Blog: The lost art of using your brain
- php|architect: Image Processing with Imagine
- PHP and Me Blog: How to Type Less $this in PHPUnit
- Brian Swan's Blog: SQL Server Driver for PHP Connection Options: Encrypt & Failover_Partner
PHPMaster.com: Taking Advantage of PHP's Built-in Server
On PHPMaster.com today there's a new tutorial for those on the bleeding edge of PHP using the latest released version (5.4) and a feature that comes with it - using the built-in webserver that comes bundled for testing purposes.
One of the cooler features of the new PHP 5.4 release is a built-in web server designed specifically for development and testing. Now you can write and test your code without having to have a full-fledged LAMP configuration - just launch a the built-in server from the command line, test your code, and then shut it down when you're finished. [...] In this article I'll explain some basic uses of the new built-in server and show you how to build a portable personal development server useful for quickly testing your applications
He starts with a look at how to start up the web server (a simple command line switch and host/port definition) and the resulting default phpinfo page it displays. Other options include the ability to specify a document root for your server and create a sort of "front controller" for it to route requests. They show how to create a simple application based on this that can dynamically load in the index file, a router and pass the request off to the correct file. Their example includes some "niceties" too like logging, "hosts allowed" and checks for requesting directories.
You can find their full code for this example over on github.
A Cloudy Place: PHPFog and Pagoda Box: A Look at PHP Platforms
On the "A Cloudy Place" blog there's a recent post comparing two of the more popular platform-as-a-service PHP offerings out there - PHPFog and PagodaBox.
Platform services like Heroku and AppEngine have been well-known for the last few years and many companies have been using them successfully in their business. They are more attractive to startups, due to low initial cost and smaller headaches involved in setup. 2011 was a great year for platform services, with the emergence of many platform services and a new trend for supporting multiple languages instead of supporting a single language. [...] Here, I will go through two of the PHP platform services I have experimented with: PHPFog and Pagoda Box.
He talks about each of the options and looks at several key elements of each including the deployment process, scalability, monitoring tools, offerings for caching and the database management utilities bundled with the application. Both services offer a "free instance" for you to try out their services, so give them both a try and see what you think.
Rob Allen's Blog: Module specific bootstrapping in ZF2
Rob Allen has a new post to his blog today looking at bootstrapping specific modules in a Zend Framework 2-based application without having to do the entire set.
Following on from the discussion on modules, we can hook into the event system to do module specific bootstrapping. By this, I mean, if you have some code that you want to run only if the action to be called is within this module, you can hook into the Application's dispatch event to achieve this.
He starts with an example of a basic module (Simple/Module.php) and shows how to define an "onBootstrap" method that calls the "onDispatch" method (when hooked to the event manager) to do some module-specific bootstrap operations. The RouteMatch feature is used to ensure that you're in the right controller/namespace combo to use the module.
2012年3月7日星期三
Community News: PHP Conference Brazil 2012 Announced
In this new post to his blog, an official announcement about this year's PHP Conference Brazil (2012) has been made:
It's official: PHP Conference Brazil 2012 will take place at UNIFIEO, in the city of Osasco (SP) Brazil from November 30th to December 2nd. Tracks for the event were chosen by the audience, through a poll we've published on Twitter: Frameworks & Tools, APIs & Webservices, Challenges and Trends, Case Studies and Successful Cases, Security and Job Scenarios.
This year's event will be happening from November 30th through December 2nd at UNIFIEO, in the city of Osasco (SP) and they're currently looking for sponsors, so if you're interested get in contact with them!
Phil Sturgeon's Blog: Packages: The Way Forward for PHP
In this new post to his blog Phil Sturgeon talks about what he (and apparently several others) think is the "way forward for PHP" to make it a better language and ecosystem - packages.
What is a package? A package is a piece of reusable code that can be dropped into any application and be used without any tinkering to add functionality to that code. [...] Most package systems also allow for something called dependencies. [...] This is how most modern programming languages work, but to make a generalisation: PHP developers hate packages. Why? Well while other languages have great systems like CPAN for Perl, Gems for Ruby, PIP, PHP has had a terrible history with package management going back years.
He talks about one of the main current packaging systems, PEAR, and how, despite its attempts, it just hasn't seen the adoption the package management of other languages has. Phil makes a recommendation that is slowly becoming more and more popular in the PHP community - building "unframeworks". These sets of reusable components (similar to the ideas behind Aura, Symfony and Zend Framework 2) are designed to be dropped in and used without the dependencies of the frameworks they live in. He points to the Composer/Packagist dynamic duo as a way through all of the current packaging issues - a simple way to make any project an installable package just by adding a configuration file.
Anthony Wlodarski's Blog: Node.js and Zend Auth with Sessions stored in the database
Anthony Wlodarski has posted a quick example of how he shared the sessions from Zend_Auth in his Zend Framework application over with a Node.js server/application.
Recently on a project I had to make changes to a underlying portion of the sites architecture to move sessions in Zend Framework from file storage to database storage. However this affected a piece of the architecture. Node.js, which manages all our real time interaction, looked at sessions at the file level. This was quite a easy transition for the function as it was abstracted away in a function call so the theory was to just replace the function "guts" with a new component.
The post shows the code he came from (which pulled in the PHP session file and extracted the session data manually) over to a new database-based version that selects from the SESSIONS table and pulls out the data. It's based on the table having an "id" column and the Zend_Auth namespace it uses.
Nikita Popov's Blog: Scalar type hinting is harder than you think
In this new post to his blog Nikita talks about scalar type hinting and why it's harder than most people think to accomplish.
One of the features originally planned for PHP 5.4 was scalar type hinting. But as you know, they weren't included in the release. Recently the topic has come up again on the mailing list and there has been a hell lot of discussion about it. Yesterday ircmaxell published a blog post about his particular proposals. The reactions on reddit were mixed. On one hand it is clear that people do really want scalar type hints, on the other hand they didn't seem to like that particular proposal.
He gets into some of the details of some of the current proposals and their problems like the strict versus loosely-typed nature of PHP and type hinting that was included but not enforced. One he does like, however, is one based on casting - how the variable ends up being cast rather than the specific type it is when it comes into the function/method. This one still has its flaws, so he suggests another method - weak type hints but with stricter input validation (without casting). He also briefly mentions something called "box based type hinting" that would allow users to define their own hinting rules.
Don't worry - code examples (pseudo-code obviously) are included for each of these proposals to help you understand the differences.
2012年3月6日星期二
Ilia Alshanetsky's Blog: Performance Analysis of isset() vs array_key_exists()
Ilia Alshanetsky has posted about a performance difference he's found between using the isset and array_key_exists functions in PHP to see if a value exists.
At Confoo I had an interesting conversation with Guilherme Blanco regarding the fact that in Doctrine 2 they had a performance issue due to usage of array_key_exists() and how it was significantly slower than isset(). His anecdotal example was that doing isset() took 0.5 seconds, while array_key_exists() for the same operation took 5 seconds! That seemed wrong [...] so, I've decided to do a quick benchmark using a 5,000 element array.
His benchmarking code is included - it just loads up a simple data set from a file of "words" and measures the microtime between the isset and array_key_exists calls. His results do show that isset is the faster of the two (by 2.5x) but it's still a super small micro-optimization that won't gain you much in the end.
The bottom line is that if your application does not need to distinguish between an array key that does not exist and one whose value happens to be NULL you should use isset() because it happens to be a little faster.
Ben Ramsey's Blog: Build PHP 5.4 on CentOS 6.2
In this latest post to his blog Ben Ramsey shows you how to, inside of a virtual machine, set up a server with PHP 5.4 installed (using CentOS 6.2).
In case you haven't heard the news, the PHP project released version 5.4.0 last Thursday. Naturally, I decided it was time to install and give it a try. I chose to install to a clean and bare-bones CentOS 6.2 virtual machine using VirtualBox. I did this for two reasons: 1) I wanted a clean environment for the build, and 2) I wanted to play with CentOS. At the time of this writing, there are not yet any official CentOS RPMs for PHP 5.4, so I had to build PHP from source. What follows are the notes I took during the installation and build process. I hope you find them helpful.
His instructions cover the full process:
- Installing the CentOS operating system
- Creating a non-root user
- Setting up the network for local access
- Installing the packages for PHP (via yum)
- Grab PHP 5.4 and compile it
- Testing out the web server with a sample phpinfo file
He includes a lot of extensions in his installation, some you may not need like pspell, tidy, calendar, ftp or xsl.
2012年3月5日星期一
7php.com: Interview Stuart Herbert - Become a Software Archaeologiest
On the 7php.com site today there's a new interview in their PHP community series, a talk with Stuart Herbert of the Phix project:
In this edition I talked with Stuart Herbert (@stuherbert), a highly highly and highly experienced software engineer. His interview is packed with insights and experienced thoughts. Herbert is one of those rare experienced geek who also teaches the principles of T'ai Chi Ch'uan. Stuart has been involved in almost everything out there in the Programming sphere; he's a conference speaker, author of books, author for magazine articles, does pod-casts, volunteer developer for Gentoo Linux, contributor and lead to open-source PHP software like PHIX, has been a founder of the University of Sheffield's Computer and Software Society growing it to over 1,800 members, and so much more as you will read below.
Questions include how he got started with PHP, his opinion of the language now versus when he started, advice to budding PHP developers and what tools he likes and uses. They also talk about his thoughts on conferences, ORMs, traits and the balance between good engineering and good management.