In this new post on DZone.com today John Esposito talks about an interesting PHP framework that has come to light lately – the Yet Another Framework, an oddly named PHP extension that provides some of the basics to build a framework-based application.
Why care about another PHP framework? especially one that’s actually called Yet Another Framework? Because Yaf isn’t just a framework. It’s a PHP extension (listed on PECL), so it’s written in C — so it’s very, very fast. How fast? Here’s a benchmark (requests/sec).
The only framework (of the list he compared) that came in faster was MicroMVC and that’s not as full-featured as the Yaf functionality is. Disregarding that, it has a huge requests/second difference between even the next on the list, CodeIgniter.
On PHPMaster.com today there’s a new tutorial that shares a few regular expression tips about doing some search and replace in your content.
So how can you practice using regex if you are limited to just using them in your code? The answer is to use a utility, of which there are many, that uses regex for performing search and replace. I’m sure everyone is familiar with the standard “find x and replace it with y” type of search and replace. Most IDEs and text editors have built in regex engines to handle search and replace. In this article I’d like to walk through a series of exercises to help you practice using regex.
His examples are based on Netbeans but can be used in just about any IDE that supports regex (or even just your code). He shows how to match word boundaries, do some grouping, work with back references and doing some search/replace based on multiple groupings.
On her blog today Lorna Mitchell has a quick tip for anyone having an issue sending POSTed JSON data with the curl functionality that can be built into PHP. The trick to her method is sending things with the right header.
We can’t send post fields, because we want to send JSON, not pretend to be a form (the merits of an API which accepts POST requests with data in form-format is an interesting debate). Instead, we create the correct JSON data, set that as the body of the POST request, and also set the headers correctly so that the server that receives this request will understand what we sent.
She includes a code example (about ten lines) showing the POSTing process that sets up options using curl’s curl_setopt. Be sure to set up the headers to send as “application/json” – that’s the trick to letting the remote end know the format.
On the php|architect site there’s a recent tutorial from Cal Evans about building a transactional email system with the help of a simple library and the SES system from Amazon.
I love APIs. A well-defined API can make short work of a complex problem. It’s even more fun when you find a cool API with a great wrapper to make it simple to use. That’s what I found when I started playing with Amazon’s Simple Email Service; a tool that was easy to work with, solved a problem I needed solved, and had a simple to use PHP wrapper.
Based on the SES library by Dan Meyers, he includes the code to pull in a simple email template and populate it with the values you want, log in to the Amazon SES service and send the email via the remote service.
Continuing on from the first part of their series, DevShed has posted part two of their “Building an ORM in PHP” series. This latest tutorial focuses on domain modeling (and collection handling).
In that first part, I implemented the ORM’s data access and mapping layers. And as you’ll surely recall, the entire implementation process was pretty straightforward and easy to follow. Of course, in its current state the ORM is still far from a fully-functional structure. We need to add some additional components to it, such as a domain model and the classes responsible for handling collections of entities (remember that the ORM relies heavily on the data mapper pattern to do its business properly).
He stays with his “simple blog” example and shows domain models (based on an abstract entity) for Entries, Comments and Authors. His containers extend the Countable, IteratorAggregate and ArrayAccess interfaces to give them some extra abilities.
On PHPMaster.com there’s a new post by Michelle Sanver about The PHP People, a.k.a the PHP community, and some of the great resources you can use to get help on a problem or just reach out and meet some other PHP-ers in your area (or at a national conference!)
If you’re ever stuck on a problem, Google it and you’ll find a swarm of users have most likely experienced the same issue and have already shared their solution. If it’s not out there, ask in a public forum and people will help you find the answer. And if you’ve managed to solve it yourself, then write about it! That way you’ll be contributing to helping others the same way others are willing to help you. That’s one part of the PHP community that makes it really stand out – people share their knowledge and are more than willing to help others along their journey with PHP.
Some resources/places to meet like-minded developers include:
The community in PHP is huge and is growing every day, and it’s all about sharing. If you see someone in need and you’re able to help, offer him guidance. If you see an open-source project that’s great; contribute and help it grow.
On Developer Drive today they’ve posted the most recent article in a tutorial series showing you how to create a user survey that stores the results to a database table. In this latest tutorial, they show how to hook the current code into a MySQL backend.
In the first two parts of this series, we created the data layer that will hold the polling data and established methods for setting the variable values and reading from the database tables. In this part, we will build the methods that will write new polls and answers to the tables.
They include the code for an “addPoll” method that inserts the questions and answers for the polls. Their “editPoll” method updates the poll questions/answers and the “addVote” method does exactly like it sounds – adding a vote to one of the poll options. Also included are “deletePoll”, “activatePoll” and “deactivatePoll”.
At Liip we have been relying on Debian and RedHat packages to deploy our web applications for some time now. For this we created or in some cases adapted some project/framework-specific solutions:
The existing solutions work very well but they’re also very specific. Since we don’t really want to reinvent the wheel for every new project/framework we decided to start looking for a more generic solution. The prerequisite was that it had to support Debian and Red Hat packages.
With fpm, by Jordan Sissel, we found a solution that can create either Debian or Red Hat packages. Basically, fpm just takes all the files inside a directory and creates a package from that.
Since the layout of the application in a development environment is usually different from the production system (on a dev environment you might have the project files in your home directory whereas in the production environment they should end up in /var/www/projectname) there was still some work involved beside running fpm. But we wanted something that was automated as much as possible: developers should only need to setup packaging once and after that they would only have to execute a simple command to build packages.
For this reason we decided to build a set of wrapper scripts around fpm. With these scripts, you just need to create a configuration file that defines the layout on the target system and some package parameters. Once you created the configuration file, a simple command creates a Makefile for you. After that, building your package is as easy as typing “make” in your project directory. What is really nice with this packaging solution it’s that it’s a) easy to use and b) platform-independent (for Debian packages at least) since you can use fpm on any platform you want.
We made the scripts available on github so other people can benefit from them. To help people get into it and demonstrate some of the possibilities of this solution, we created a demo project that you can try to package and deploy. If you just want to build Debian packages you can just install fpm and you should be good to go (it even works on OS X, so you don’t need a Debian machine to create packages). For rpm packages you unfortunately still need rpmbuild.