Debugging PHP With Firebug
February 8th, 2007
Logging PHP and JavaScript errors to same window makes debugging easier. It also might be the cure to cancer and bring world peace. In general…
In a recent PHP + JavaScript project I realized how annoying it is to have debug information in more than one place. For PHP I use PEAR::Log package. Log is written to file. For JavaScript I use Firebug. Log is written to Firebug console. When something goes wrong you must switch between browser and terminal windows.
There must be a better way. I like both PEAR::Log and Firebug. Obvious thing was to combine them. Result is Firebug handler for PEAR::Log. It can currently be found only in CVS. Hopefully be handler will be included in next release of PEAR:Log package.
Example PHP usage below.
$log = &Log::singleton('firebug', '', 'PHP',
array('buffering' => true),
PEAR_LOG_DEBUG);
$log->log('Debug lorem ipsum.', PEAR_LOG_DEBUG);
$log->log('Info wisi enim ad minim veniam', PEAR_LOG_INFO);
$log->log('Warning est usus legentis in', PEAR_LOG_WARNING);
$log->log('Error est notare quam', PEAR_LOG_ERR);
If you have Firebug installed, enable it and check Log Firebug test page. You can also redirect all PHP errors to Firebug console.
UPDATE 20070208: You might want to check FirePHP which provides different approach. FirePHP is Firefox extension built on top of Firebug. It modifies request headers to include Accept: text/firephp. Debug data is sent back using text/firephp section of multipart/mixed HTTP response. Using FirePHP is more complicated but at the same time it can provide you with more flexibility.
Valentine Day Cards With jQuery and PHP
February 7th, 2007
We just finished latest joint project with finnish EGO. Result is Valentine’s Day card campaign for the main newspaper in Finland. Users choose between six prefined picture frames. Upload best picture of themselves (photoshopped or not). Write a nice poem to their loved one. After the masterpiece is finished they can send the card immedietly or at chosen time.
Typical way of working in advertising world is not most pleasant. Insane deadlines. Clients doing last minute changes. With these things in mind, you can not spend too much time coding basic things. With jQuery we were able to concentrate on needed features:
- Photo should be zoomed with magnifying glass icons.
- Photo should be panned by dragging it with mouse.
- Greeting text should be previewed live while typing.
- No Flash.
Campaign site also uses date picker plugin by Kelvin Luck
IP Address to Country Code Conversion
September 8th, 2006
Having been almost one year in my TODO list I finally updated the documentation section of I18N_IP2Country.
ISO 3166 Country Code PHP Class
March 18th, 2006
Old code gets updated because I am bored. I do not feel drinking and I have not found any pinball machines in Tallinn yet.
I18N_ISO_3166 is an old class which I have neglected for a while. Quick look on ISO website shows some updates I have missed. Yugoslavia has been removed. �land Islands and Serbia Montenegro has been added. I also shortened the official names of countries. There was no point including The Republic of after every other country.
Ford Henry Cars
January 23rd, 2006
First joint Internet project between our Tallinn and Helsinki offices went just live.
Henry badge is a guarantee that the used car is sold by an official Ford dealer and it was throughoutly checked by Ford engineer. Ford Henry website itself is a visual way to browse used cars which have the Henry badge.
The car data is fetched from Netwheels database – a company which hosts most of carsale dealer data in Finland. The logic itself is built around DB_DataContainer, PHPSavant, Cache_Lite and PEAR::DB. And yes, it validates.
I18N_IP2Country - IP Address to Country Code Conversion
September 19th, 2005
Provides methods for retrieveing country name or ISO 3166 country code based on ip address, ie. ip to country conversion.
I'm back, this time armed with Textpattern
September 17th, 2005
Since there will be some changes in my life which I wanted to document (you know, so I will remember them later) it became mandatory that I ditch my old homebrewn system and change something easier to use. This way I won’t have the excuse of it’s so complicated for not writing. I looked into several different softwares…
WordPress: Everyone uses it, written in PHP – the language of my choice. But it just does not feel elegant. If it does not feel right it just does not feel right.
Typo: Propably the most hip blogging system at the moment. Written using Ruby on Rails. Utilises AJAX in several places. The downside? Installation, definetily installation. It was like compiling PHP in 2002 – trial and error. In the end I just could not make it work properly with ~username/ style URLs. Then I gave up.
Serendipity: Written by several of the best PHP developers on earth. The code itself is superior but what Serenpidity really needs is a couple of designer guys and a user interface specialist onboard with the developer team.
Texpattern: This is what I finally chose to use main reason being usage of Textile for post formatting. Textile together with somewhat different aproach to admin interface gives Textpattern an elegant overall feeling. The permalink style is similar to my old permalinks so I will not loose my google status. It is not all good though. The template system is a bit awkward and the PHP code itself is really not my style. But hey! It Works™ and I don’t have to maintain the code.
Persistence Layer For PHP5
October 18th, 2004
The latest releace candidate of DB_DataContainer now supports also PHP5. Official release will follow shortly if no bugs are found. Also to those who might be interested a port to PDO is under its way. The class will be called PDO_DataContainer.
While browsing through similar projects I found out something that I haven't noticed before. Propel uses the same approach of having just one save() method instead of separate insert() and update() methods to persist the object into the database. I never understood the reason of having different method call for INSERT and UPDATE which is what most of the persistence layers and alike have. If the object has primary key set you know you have to do an UPDATE. If primary key is not set you know you have to do and INSERT.
Daniel Convissor Speaks PEAR::DB
June 24th, 2004
In the latest edition of International PHP Magazine Daniel Convissor gives an overview of the new Features in the PEAR::DB 1.6.x releases. The article is called PEAR DB: Ripe for the Picking.
Two solid months of tilling the proverbial soil, committing over 500 bits of fertilizer and squishing 90 documented bugs—and countless undocumented ones—has brought PEAR’s most popular package to a new state of maturity. It is stable and fully tested on most of the supported DBMS’s. The new release focuses on portability, allowing you to write applications that can be used with a wide variety of database back-ends.
Savant - a No-Nonsense Templating Engine For PHP
May 6th, 2004
For years I have disliked all the templating engines for PHP. IMNSHO the whole concept of templating engines for PHP does not make sense. In order to have a flexible templating engine it must have a flexible scripting language. Why in earth you would want to write a scripting language parser with a scripting language such as PHP.
Friends don’t let friends use templating engines.
Today I found Savant. After spending a good hour reading the docs I started to realise it is a templating engine I could use. It has a no-nonsense aproach. It uses PHP as the template language, but still provides a nice interface to separate business-logic from display-logic (something I should pay more attention sometimes). As a promise to myself, I will investigate more on Savant. Perhaps first use vanavesi.com as a testbed and initial testing.
Because you still want to separate your business logic from your display logic.