Recent Blog Posts
Blogs » PHP
Dynamically Typed
: PHP BlogRasmus Lerdorf: PHP Frameworks? Think Again.
This is the fist time I have heard Rasmus Lerdorf speak and it was entertaining to say the least. Refreshing would another way to describe it, I enjoy hearing real opinions and not holding back — Rasmus doesn’t hold back.
Just a short background, Rasmus Lerdorf is the creator of PHP and still continues as a core developer to the PHP project.
PHP frameworks
In his address he choose to highlight PHP frameworks (Drupal was not spared) and how poor they are at performance. Not only are they slow, but their "jack-of-all-trades" attitude leads developers down the wrong path by not using what is best for the job. He continues on by stating that PHP developers really need to think about performance for not only scalability reasons but for green reasons. If programs were more efficient it would cut the number of data centres and would reduce energy needs as a result. In our newly emerging age of energy awareness this does become an important aspect and I am glad that he is raising awareness.
Back to frameworks, he started by discussing a database heavy Twitter mashup that he created. This does a lot …
Mangling XML as Text with PHP DOM
Recently I had to do some mass-conversion of HTML files to DITA XML — material I’d written for the upcoming JavaScript Ultimate Reference (the third, and arguably most complicated, part of the SitePoint Reference).
But a problem I came across several times was the sheer complexity of recursive element conversion — <code> becomes <jsvalue> (or one of a dozen similar elements), <a> becomes <xref> … and that’s all simple enough; but each of these elements might contain the other, or further child elements like <em>, and as we walk through the DOM so the incidence of potential recursion increases, until it gets to the point where my brain explodes.
There’s a limit to how much recursion I can get my head around — or rather — a limit to how much I’m prepared to get my head around before I just go the heck with this, why can’t I mangle it as text with regular expressions!?
Unfortunately there doesn’t seem to be a way with PHP DOM to get the text equivalent of any arbitrary node, but we can do that at the Document or DocumentFragment level; so with a little toying-around I came up with a way to leverage that capability and …
Keeping Current With PHP
Just a quick hint to people with an interest in the development of PHP, but no time for following php-internals. Since March, there has been a wiki at wiki.php.net. The most interesting section is probably wiki.php.net/rfc, which - as the name implies - contains RFC’s for improvements of the language. I’ve rambled on about closures and lambdas before, but as you can see, there is now an accepted patch. Whether it’ll make it into 5.3 is unlikely at this point, but it looks like it’ll at least be coming with 5.4 and/or 6.0.
While we’re at it, Steph Fox have dutifully been writing up summaries of php-internals discussions on a weekly basis since the beginning of time. If you just want to get the headlines, it’s an informative read.
Have a nice summer.
Last we checked, PHP IS a framework.
When it comes to web programming languages, PHP probably holds the record for copping criticism from the community at large. Comparisons with alternatives such as Ruby on Rails and Python/Django are common; defenders of PHP are quick to criticise the comparison of a language and a framework. But at the end of the day, developers work with Ruby on Rails, and with Python/Django, and with PHP. Just PHP. For most of the PHP applications out there, the language is just perfect, because PHP, to an extent, is the framework.
PHP is designed for the web. You could plug vanilla Ruby or Python into a web server and get up and running pretty quickly. But, at least at a basic level, you’d want a framework to deal with common issues of web development. In PHP, you just get started. PHP and Apache work out request data, output handling and more, right out of the box. (PHP also masters deployment.) David Heinemeier Hanson, the creator of the Ruby on Rails framework, calls this the immediacy of PHP.
Now, consider the “average” PHP frameworks. They help you handle request data, manage your output, control app flow - essentially, extending …
PHPBench.com: Live PHP benchmarks, demystifying “best practices”
As a new contributor to the SitePoint blogs, I’ll be covering PHP web development, JavaScript and general web tech.
When it comes to optimizing PHP for performance, there’s no end of resources available, and no end of conflicting opinions either. Everyone seems to have their own approach to writing “fast” PHP code; using single quotes, avoiding require_once() and using isset() before is_array() are some of the most common. But with reliable benchmarks thin on the ground, how do we know if any of these techniques - often touted as “performance best practices” - actually deliver benefits? Chris Vincent’s new PHP benchmark suite at PHPBench.com aims to “set the record straight” on PHP performance techniques, with a simple, comprehensive view of how various approaches actually stack up.
The benchmark suite covers all the usual bases, taking a simple task — like iterating over an array — and speed testing almost every possible way to achieve it. Most importantly, however, Chris takes raw numbers out of the spotlight and instead focuses on how the options compare with each other. Each test takes the fastest technique as the base value for execution time; all the other options are measured as percentages in relation to this. …
Debugging PHP
I just checked in a little project, I’ve been working on for the last couple of weeks.
It really begun at the last Copenhagen php-meetup; Joakim Nygård and Jacob Oettinger made a presentation of their project, WebCacheGrind. I casually mentioned something about having played with the dbgp-protocol (The debugging part of Xdebug) and that it ought to be simple enough to write a fontend for it. That prompted some snickering from the back row. Apparently some guys had this rule at their workingplace, that whomever said that something ought to be easy to do, had to do so himself. Not an unreasonable rule, I suppose. Obviously, I couldn’t let that go unattended, so I gave it a shot.

Spectator is a XUL application, which should make it cross platform. I have tinkered a bit with XUL before, but not a full application. If you’re wondering what XUL is, it’s the GUI toolkit, in which the frontends for Firefox and Thunderbird are written. It’s a markup language — much like HTML, which can be scripted with Javascript. This makes it very easy to work with. The only problem seems to be a rather …
Useful in-browser development tools for PHP
While debuggers exists, there isn’t much of a tradition for using them in PHP. People have largely come to rely on injecting debugging code directly into the program, for inspecting program scope. The infamous var_dump have served for this purpose and version 4.3.0 of PHP brought us another equally useful function — debug_backtrace.
Tracers and error handlers
Both of these functions produce a rather crude output though, so naturally people have written wrappers around them to remedy this. I think Harry’s pretty bluescreen was one of the first dedicated libraries I’ve seen. Xdebug spouts a similar output on error, although arguably not as pretty. Or blue.
What bluescreen is for debug_backtrace, krumo is for var_dump. Recently, FirePHP — building on Firebug — does a similar thing. FirePHP uses HTTP-headers to send data from server to client, which turns out to be very handy when dealing with non-HTML output (Eg. Ajax stuff). Because it builds on Firebug, it only works on Firefox, and in particular only on Firefox 2 (Another reason for Ubuntu-users to downgrade from Firefox 3).
Frameworks
Apart for these general general tracing tools, a couple of frameworks have their own, more or less specific, tools. Symfony’s Debug Toolbar is probably the most impressive …
A PHP Guy’s Look At Python
Against all odds, I found myself with a little spare time this week. Rather than do something sensible like clean the garage or get some exercise, I took the opportunity to learn a new programming language: Python.
Like may SitePoint readers, I cut my teeth on PHP. I’ve become very comfortable with it over the years, warts and all. PHP continues to be a dependable choice, but PHP hasn’t changed a whole lot lately. Meanwhile, the kinds of applications I’ve been working on have been growing dramatically in both size and complexity.
Python has a lot in common with PHP: it’s a dynamically typed, open source scripting language with excellent documentation and a thriving community around it. Both languages are also a little quirky when it comes to their handling of Unicode text.
Unlike PHP, Python wasn’t originally designed as a language for Web development—it’s a general programming language that just happens to have some excellent libraries and frameworks for building web sites, like Django. This may sound like an argument against Python, but it turns out that when you start writing bigger web applications, most of your code has nothing to do with HTML, and PHP’s HTML-friendly features just seem to …
Drupal 6.0 Released
The Drupal development team surprised everyone when they released version 6.0 last week, ahead of schedule.
After one year of development we are ready to release Drupal 6.0 to the world. Thanks to the tireless work of the Drupal community, over 1,600 issues have been resolved during the Drupal 6.0 release cycle. These changes are evident in Drupal 6’s major usability improvements, security and maintainability advancements, friendlier installer, and expanded development framework. Further, from bug fix to feature request, these issues follow-through on the Drupal project’s continued commitment to deliver flexibility and power to themers and developers.
While I haven’t used Drupal on any major projects, I got to see it in action in the FullCodePress international site-in-a-day competition last year, when the Australian team chose it to power their charity’s site. And when I attended Drupal MiniCon here in Melbourne a couple of weeks ago, a recurring theme was that the installer needed to be friendlier for first time users.
I’m happy to report that, with the version 6.0 release, getting Drupal up and running is as easy as it should be, and the Lullabot team have prepared an excellent screencast (MP4, 12 minutes, 38.5 MB) that anticipates …
What’s so bad about the Singleton?
I keep running into people who caution against using Singleton and recommend to avoid it like a plague. What is so scary about it?
— Kailash Badu
It’s a good question, for it is true that global variables are often demonised and more recently the Singleton has befallen the same fate. Perhaps a bit surprising, it is remarkably hard to find good arguments to support this common knowledge — Googling turns up a lot of confusion.
As I have often taken this stance myself, I found it reasonable that I should be able to argue for it, so I’ll try to give an explanation. This is also in part a follow-up on my post from last week, in which I present a way to avoid global symbols, without spending much time on why.
The anatomy of the Singleton
Some of the confusion around Singletons, comes from the fact that it is a manifestation of two different concepts, which each have a negative effect on an applications architecture. This muddies the case, since people tend to only deal with either one or the other of these two.
The most obvious of these concepts, is that the Singleton is a form of global state. It has this …
Sponsored Links
SitePoint Marketplace
Buy and sell Websites, templates, domain names, hosting, graphics and more.
Want More Traffic?
Get up to five quotes from qualified SEO specialists, with no obligation!
Download sample chapters of any of our popular books.



