« Archives in December, 2008

2 tips – Check PHP syntax and SVN move multiple files

This is what I have in my .bash_profile. It check for all the PHP files, recursively, for any syntax error.

alias php_check_syntax='find . -type f -name \*.php -exec php -l {} \;'

This other tip is to move multiple files in SVN. You can make it a script if you want.

for i in *.test.php ; do svn move $i tests/ ; done

TextMate – Search in project

Several issues I would suggest to the developer:
1) When searching, there is no status/progress indicator (or the button flashing very lightly that I do not notice, but a turning icon would be much nicer). For a large project with over 1000 files, one would wonder if these are all the result or it’s still searching.
2) There is no total/summary that let you know how many matches found.
3) The Replace All option is very nice, however, it does not save the files yet and the icon will be grayed out (if you open its folder). Otherwise, you would not know. Some files are not saved, even if you close all the file windows. You would need to click Save All to save the changes. Even though it should not save the file automatically and an explicit user action is required, an indicator of the project status would be nice.
4) If the result has a long text line, there is no horizontal scroll bar

It’s a great editor and I quite easy to work with.

First snippet customization in TextMate

After reading the manual and view the bundle, customization is quite powerful in TextMate. This class declaration should be trigger by typing “class”, then press Tab key. It automatically your full name using finger/whoami and set the date. Pretty neat eh!

XAMPP vs. doing it your own

Thinking that I would have more control by setting up the packages by myself, I was wrong. After running into the problem with pre-installed PHP by MacOS X Leopard does not have GD, IMAP and other components, I tried playing with fink, MacPorts and manual compiling. LAMP still rules and not “MAMP” for good reasons. Although Mac is quite dev-friendly, it still takes hours searching and setting up. I find the binaries under Linux/CentOS (eg: yum install/update php-gd) much easier to deal with.

I guess I learned from the process but it would be much simpler to go with XAMPP. The conf files are in one place, easy to find and getting it up and running is really simple. If you plan to have a dev environment, don’t bother with the manual installation that can take hours. Now this Mac is ready for some development.

Convert from PC to MacBook for a developer

With the new nicely looking MacBook and an old PC, plus some decent deals on Amazon, it’s a good time to switch. After a couple days, this will be a productivity improvement. Many packages are available and ready to use, like svn, httpd. Here is maybe a list of things I did for a conversion:

  • Install the LAMP stack: Apache/httpd (already ready, just need to enable on System Preferences, edit the httpd.conf for fine-tuning and remove modules), MySQL (download the package from MySQL.com and setup a plist file for launchd, a better approach to start/stop services), PHP (only need to uncomment a line in httpd.conf)
  • Setup SVN (already as a bundle in TextMate, moving repositories from PC with svnadmin dump, quite simple)
  • Install TextMate (on PC, I use EditPlus, so this is similar, or even better, IDE is not my thing, too bloated, no matter how nice)
  • Setup Spaces (esp. the application assignment): this makes up for the smaller screensize (13.3″)
  • KeePassX: a port from Keepass, an open source project, looking for its iPhone coming up
  • Terminal: customize the preferences to your favorite colors (for many devs, probably a dark background). This is one of the many things that draw me to a Mac, a familiar command-line together w/ a beautiful/elegant GUI.

CakePHP – Simple User Registration

After doing some initial readings on different PHP frameworks, including CakePHP, CodeIgniter, Symphony, Zend. I’m digging deeper into CakePHP with an open eyes for fresh ideas and other developments. To start, CakePHP is slow, quite slow (backed up by Rasmus’s benchmark at froscon). It also has not taken advantage of more object-oriented syntax and methods. That said, there are many neat ideas in CakePHP that we can learn to incorporate into our in-house high performance framework (but with less features and automagic).

Framework Performance

To those who says that “slow frameworks is acceptable or understandable”: good framework scales both in term of performance and functionality. It should be easily extensible from its tiny core. Software that does not use any framework cannot scale to provide more functionality and can offer good performance only at a simple task. Enough rants, let’s get dirty.

First App

This is a simple user registration. Cake does have its way of doing things and you might or might not like it. I’m not a big fan of $validate, $uses, and such. I do hope CakePHP will use more PHP5 and OOP the sooner the better since it’s a good framework.

User Model

User Controller

View – register.ctp

Google AdWords – Click Fraud Rate

Google believes the click fraud rate is less than 2%. The facts support the opposite and click fraud is running rampage on Google’s networks, including their search sites. For us, we only leave about 5% impressions/clicks on AdSense, which has a much lower quality than Google-operated sites.

Clicks: 314
Invalid: 67
Click Fraud Rate: 17.59%

Click fraud is a big problem for any advertiser. We’ll have to be more careful in monitoring and allocating our advertising budget.