Archive for September, 2007

September 24th 2007

Terry Chay: Why PHP triumphs over Ruby

Terry Chay writes another hilarious post about PHP vs. Ruby

“I’m really low on my scatological count here…I’m sorry I didn’t crack enough jokes or use enough [cuss words], but I’m sure people will forgive me. They can just attend one of my talks and get their cuss quota for the year. And if not, coding these web apps themselves involves a lot of swearing—a lot of blood, sweat and swear.”
—me on Pro PHP Podcast

I’m not posting my talk yet because I have to give it again at ZendCon. So here is a bit of a teaser.

[Do not hit the jump if you are easily offended. I really mean it!]

No Comments yet »

September 15th 2007

Being nice With Long Processes

Every once and a while, I find that I need to compile code on a machine where many other more important things are running. In my case, I generally find myself recompiling PHP on a machine that also runs my very active forum website [http://forums.reebosak.net] in addition to many other websites, including this one. Running a long build is not exactly the nicest thing to do to users who are trying to go about their normal browsing, where a long build would cause really long page loads since the processor is so busy. The way to deal with this is by being nice (and renice).

from the UNIX man page:

NAME

       nice - run a program with modified scheduling priority

DESCRIPTION

       Run  COMMAND  with an adjusted niceness, which affects process schedul-
       ing.  With no COMMAND, print the current  niceness.   Nicenesses  range
       from -20 (most favorable scheduling) to 19 (least favorable).

To set a processes niceness run it with the nice command:

[brien@toothbrush ~]$ nice -n 5 make // run make with +5 niceness (lower priority)
[brien@toothbrush ~]$ ps aux |grep make
brien      4560  0.0  0.1  5040 1180 pts/1    SN+  18:36  0:00 make
[brien@toothbrush ~]$ sudo renice -3 4560 // change the niceness of the process to -3 (higher priority)

No Comments yet »

September 11th 2007

Auto Converting PHP Objects to Strings using the __toString() ‘Magic Method’

Ever wished there was a way to echo or print a PHP Object as if it were just a string and have it print something more usefull than Object id #1? In PHP5+ there is a Magic Method __toString() that will allow you to specify how you want your Object to react when converted to a string.

<?php
class Person{
  private $firstName="Brien";
  private $lastName="Wankel";
  private $age="30";
  ...
  public function __toString(){
      return "{$this->firstName} {$this->lastName}";
  }
}
$me = new Person();
echo("My name is {$me}"); // prints: My name is Brien Wankel
?>

No Comments yet »