• March 31, 2007

    PHP Optimization Tips – The Balkan way!

    Lately I became obsessed with a speed and optimization of PHP web applications. Namely, we are currently working heavily on a new release of voodoo [vudu] (a content engine we built using our in-house developed framework which utilizes few common PHP design patterns). I guess that ActionScript optimization got under my skin and now it's kicking in into PHP front. :) We are reinventing the wheel, but hey - what else would we do? Play Quake all day long? :)

    Soooo, I did some benchmarking, I did some reading, and this is what I've came up so far:

    1. If a method can be static, declare it static. Speed improvement is by a factor of 4
    2. Avoid magic like __get, __set, __autoload
    3. require_once() is expensive
    4. Use full paths in includes and requires, less time spent on resolving the OS paths
    5. See if you can use strncasecmp, strpbrk and stripos instead of regex
    6. preg_replace is faster than str_replace, but strtr is faster than preg_replace by a factor of 4
    7. Error suppression with @ is very slow
    8. $row[’id’] is 7 times faster than $row[id]
    9. Single quotes are faster than double quotes
    10. (42 == $foo) is faster then if ($foo == 42)
    11. ++$i is faster than $i++
    12. true is faster than TRUE, And 1 is even faster than true
    13. Calling isset() happens to be faster then strlen()
    14. While is faster than do while:
      while (--$i) { //do nothing }

      as opposed to

      do { //do nothing } while (--$i);

      And this performs even better:
      for ($i=0; $i++<$count; ) { ... }

    15. Using persistant over non-persistant DB connections in mysql can increase number of requests per second by 41%
    16. You can save yet another 40% of time spent for parsing and compiling by using an opcode cache like APC
    17. References do not provide any performance benefits for strings, integers and other basic data types. In contrast, functions that accept array and object parameters have a performance advantage when references are used. This is because arrays and objects do not use reference counting, so multiple copies of an array or object are created if "pass by value" is used. So the following code:
      function ObjRef(&$o) { $a =$o->name; }
      is faster than:
      function ObjRef($o) { $a = $o->name; }
    18. In PHP 5, all objects are passed by reference automatically, without the need of an explicit & in the parameter list. PHP 5 object performance should be significantly faster.
    19. Fastest PHP Input filtering comes as a filter extension built in PHP 5.2 and is available for 5.1 as a separate download. There is a good tutorial on zend devzone
    20. The ctype extension offers a series of function wrappers around C's is*() function that check whether a particular character is within a certain range. Unlike the C function that can only work a character at a time, PHP function can operate on entire strings and are far faster then equivalent regular expressions.
      preg_match("![0-9]+!", $foo);
      vs
      ctype_digit($foo);
    21. Internally arrays are stored inside hash tables when they array element (key) is the key of the hashtables used to find the data and result is the value associated with that key. Since hashtable lookups are quite fast, you can simplify array searching by making the data you intend to search through the key of the array, then searching for the data is as simple as $value = isset($foo[$bar])) ? $foo[$bar] : NULL;. This searching mechanism is way faster then manual array iteration, even though having string keys maybe more memory intensive then using simple numeric keys. Second example is is roughly 3 times faster.

      $keys = array("apples", "oranges", "mangoes", "tomatoes", "pickles");
      if (in_array('mangoes', $keys)) { ... }

      vs

      $keys = array("apples" => 1, "oranges" => 1, "mangoes" => 1, "tomatoes" => 1, "pickles" => 1);
      if (isset($keys['mangoes'])) { ... }

    Some tips may be completely out dated or completely wrong due to different hardware/software configurations on systems used for benchmarking.

    And for over-obsessed characters - I've found interesting articles about how stuff is handled differently in php5.1 and 5.2 opcode - compiled variables and strings.

    Sources: moskalyuk.com, whenpenguinattacks,
    iBlog, phpLens, wikimedia, phpbench, php.net, php.net - migration,

  • March 29, 2007

    The Exorcism of ATI Catalyst

    Last week I installed new 7.2 ATI Catalyst drivers on my rusty XP dev machine. The second I rebooted I got errors from Hell popping up!

    Just take a look at the pictures. Pretty self explanatory. :) The first snap is my favorite. Cmon, everything worked fine with 6.x drivers, and now this. :(

    update: Catalyst 7.3 was released last night! Errors are gone!

    [photopress:Snap1.png,thumb,pp_image][photopress:Snap2.png,thumb,pp_image][photopress:Snap3.png,thumb,pp_image]

    Faulting application CCC.exe, version 2.0.0.0, faulting module imon.dll, version 2.51.8.0, fault address 0x0000d039. Faulting application MOM.exe, version 2.0.0.0, faulting module imon.dll, version 2.51.8.0, fault address 0x0000d039. Faulting application , version 0.0.0.0, faulting module unknown, version 0.0.0.0, fault address 0x00000000.

  • March 27, 2007

    Adobe announcement galore!

    On March 27, 2007, at 3:30 p.m. Eastern time, Adobe Systems will host a webcast of the official launch of Adobe® Creative Suite® 3, live from New York City. If you are not in New York, you can check out webcast here! This is only an announcement, the software is going to be actually shipped later in the spring'07.

    The long awaited public alpha version of Adobe Apollo is out in the labs.

    [photopress:adobe_070325_adobecs3_lg.jpg,full,pp_image]

  • March 23, 2007

    hardware vs. software

    I have recently reinstalled OS, and i was once again reminded how most of the software development companies suck donkey balls by making stupid oversized and bulky software. Over time simple software grew in size and (unwanted) capabilities and is cluttering memory and everything else on the computer. First versions of, for example, Winamp and Nero Burning Rom, were awesome. Winamp played my MP3s and Nero burned my CDs. They loaded lightning fast, took no memory space whatsoever, and were non obtrusive. Today, after i reinstall my OS, i postpone as much as it is possible installation of such software.

    New version of Nero has so much stupid features that my head hurts when i double click the install file, and i would rather use Winamp 2.0 then this "next generation" crap. And the core functionality of them is the same, they still play MP3s and burn CDs. Percentage-wise, old Winamp took about 2% of my RAM when my memory was measured in few megabytes. Today, when my RAM measures gigabytes, Winamp still takes about 2% of my RAM. Hello? Where is the progress in that? One good example is Photoshop's "Batch" ability. Photoshop can save an action (for example, resizing image to 50% of original size), and then you can apply that action to an entire folder of images. Photoshop opens each image, resizes it, saves, closes that image, and opens up new one, until all the images are processed. I swear that 6 years ago, running hardware that is at least 50 times inferior than my box today and running up to date Photoshop (then and now), it took SAME amount of time to do that as it does today.

    Software developers will defend their point of view by saying "Well, we got more hardware resources (memory, disk space, CPU), so we are using it". I say - NO dudes, NO, we got more hardware resources so we can run things FASTER, not run them at the same speed we were running them 10 years ago just because new crappy features were added. What is the point of upgrading hardware, when new software instantly kills your computer?

    Daemon, out.

  • March 16, 2007

    Social networks are taking over!

    Today I joined two of them! :) The Great Game Experiment, a community site especially for gamers and game developers. Members can introduce their favorite games, add new games, meet other gamers/developers etc.

    iJiggis a web application (slash network) similar to digg or youtube but for music. You can upload, share etc, your music. They have nice mp3 player.

  • March 14, 2007

    Stopping new “Cold War” (TM)

    So anyways, yesterday on Digg there was a link to an official hacked activation of Windows Vista. Team Paradox managed to crack their way through ways of actually activating Vista, not just stopping the 30 day counter. Basically, it is one of the most hard core hacks that I ever saw, I will not go into the details how it works. Of course, it triggered an eternal topic - why do software companies try at all to "protect" software, since anything can be cracked?

    The answer is simple. USA government is, of course, putting pressure on Microsoft to invent new security systems in order to keep hackers busy. Imagine what would happen if all those ultra smart people had noting to do all day! Russian hackers would start digging around Pentagon, and in a matter of days we would have new Cold War. Keeping hackers busy makes the World a safer place. Microsoft is actually promoting World peace!

    Just to be on the safe side, I will put a smiley face. =)

  • March 12, 2007

    Strange paintings

    [photopress:rv12a.jpg,thumb,pp_image][photopress:2u1fa.jpg,thumb,pp_image][photopress:grawa.jpg,thumb,pp_image][photopress:prroa.jpg,thumb,pp_image]

  • March 9, 2007

    LASER

    I want this Laser to be available RIGHT NOW for everyone.

  • March 8, 2007

    Live.com

    I have done the unimaginable, the inexcusable, the horrible. I changed my Home from Google.com to Live.com, Microsoft's search engine. Let's see how will this little test do.

    Update, 24 hours later: back to Google. Basically, it is a replica of Google (has "define:" and has spelling correction, etc..), only it takes considerable amount of time to load, and if you pimp it to resemble NetVibes it falls apart from time to time on Firefox. I had to give it a go though.

    Daemon out.

  • March 7, 2007

    Progressive Enhancement with Flash take Two!

    While we are waiting for SWFFix to come out, which will solve all Flash embedding problems :), SWFObject 1.5 has been released. James Eberhardt is working on a SWFObject addon called SWFResize which will hopefully solve start in full screen Flash (8) problems.

    The great sIFR 3 rev 229 is out and it contains many fixes and improvements (new automatic ratio approximation, fixed leading for single-line text, delayCss...)

    And finally - swf Image Replacement. swfIR is here to solve some of the design limitations of the standard HTML image and its widely-accepted associated CSS values, while still supporting standards-based design concepts. He he, don't know how will Rick James react when he sees this. :)

Proudly running on Word Press, and above all, proudly using Comic Sans.

Nivas.hr © Copyright 2009    All right reserved    Made in Croatia Yeah, we made our own site!Nivas.hr