Client-side developers always had it easy - libraries such as jQuery and Prototype make finding elements on the page reliable and efficient. In PHP, regular expressions tend to get rather messy, DOM calls can be confusing and verbose, and often the string functions just aren’t enough. In this tutorial, I’ll show you how to use the middle ground - the open source PHP Simple HTML DOM Parser library, which provides jQuery-grade awesomeness for easy screen scraping without messy regular expressions. (more…)
It’s not easy being a web developer - in addition to a server-side language, we also have to learn a markup language, yet another (client-side) language and a presentation system. As a result, we tend to focus on what we’re closest to - the business logic - and neglect the front-end.
But you don’t have to be a web dev guru to build great applications: with just a few simple tricks, you can make your web based interfaces more usable and more visually appealing. Here are a few simple CSS tricks every PHP / web developer should know. (more…)
For anyone who’s ever tried to fetch multiple resources over HTTP in PHP, the logic is trivial, but one key challenge is ever-present: latency delays. While web servers have perfectly good downstream links, latencies can increase script execution time tenfold just by downloading a few external URLs. But there’s a simple solution: parallel cURL operations. In this tutorial, I’ll show you how to use the “multi” functions in PHP’s cURL library to get around this quickly and easily. (more…)
FirePHP is a plugin for Firebug, the web development plugin for Firefox, that allows PHP scripts to talk to a Firebug panel. FirePHP installs alongside Firebug, and provides a simple PHP library to bridge the two. FirePHP provides a window of insight into your PHP applications, with a simple debugging interface that won’t interfere with your page content. If you already use Firebug on PHP-powered applications, FirePHP is definitely worth a look. Here’s a quick guide to getting started. (more…)
So you’ve just built a fantastic processing routine for your application. You’ve checked and double checked the integrity of user input, and you’re doing some serious processing. There’s only one problem: it’s too slow. There’s a simple solution: forking your processing script, and running the code as a background process asynchronously. It can email your user when it’s done: they’ll wait. In this tutorial, I’ll show you how to get started with background processes in PHP. (more…)
We recently looked at front-end testing of web applications with Selenium. Today, we’ll take another approach to testing your PHP applications: backend unit testing for your actual PHP code. As part of our posts on test driven development, here’s a quick intro to using SimpleTest to test your PHP applications. (more…)
ORM, or Object Relational Mapping, is a database design approach that simplifies managing complex databases for programmers. Instead of direct database access, an ORM layer in a PHP framework can make “objects” stored in a database behave like actual objects from a programming perspective - for example, creating a new “car” stored in the database could involve a call to $car->new(). By abstracting actual database access, web development can be more productive and result in more reliable applications. Here’s a quick intro to ORM in PHP. (more…)
$car->new()
Often you need solid metrics on the performance of your web application. Benchmarking your website can provide insight into which sections of your application might need major optimizations, and helps in dealing with scalability issues. Apache Bench, or ‘ab’, is a command line load testing utility which ships with Apache, and allows you to simulate load on a web server. In this tutorial, I’ll show you how to get started with ab. (more…)
Over on the AVNet Labs blog, Ekerete Akpan has posted a few results from his recent framework benchmarks to much controversy. His tests covered a few major PHP frameworks, such as CodeIgniter, CakePHP and Zend Framework, along with baseline results for serving static HTML and procedural PHP versions of the same page. He also covered some basic Ruby on Rails, including Passenger (mod_rails?) and Ruby Enterprise. Here are some of his more interesting findings. (more…)
As PHP applications grow in size and complexity of structure, developers often find themselves putting together a “deployment plan” - that is, a set of steps to go through each time they want to take the code and package, deploy or test it. This process could involve creating some deployment-specific configuration files, packaging up the code, storing the current state in version control, even setting up the database. Phing is a build system for PHP, based on Apache Ant, that aims to automate many of these processes and simplify application deployment for PHP developers. (more…)