• September 10, 2007

    PHP4 must die!

    Harsh as it may sound, lately the web is full of headlines like that. Why, why!? Mass panic mode activated! What does it all mean?? The end of PHP as we know it?

    The PHP development team finally announced end of life for PHP4. After 2007-12-31 there will be no more releases of PHP 4, and critical security fixes will be available until 2008-08-08. After that, you are running php4 on your own risk, and we all know how risky the business Internet is. Do you still have Windows NT 4.0 or RedHat 7.1 on your servers? Are they developed or supported? No!

    It was about a damn time they let go php4. PHP5 has been available for 3 years, and hosting companies have had plenty of time to make the switch. From developer standpoint I have absolutely no sympathy for those who have left it until the last minute, and even then needed to be pushed. I understand the problem they have - they didn't realize the importance of php5. And now gazillion of php3/4 sites (which make a large majority of php users) have to be "upgraded". What will happen to them? PHP dev. team could avoid this hassle, by just plotting the php's development road map better, and being more direct with timelines. They are still doing it wrong, since they are killing php4, and not giving enough info on forthcoming PHP6.

    Our migration was also being dictated by hosting company. We asked our provider for php5 in the beginning of 2006, and begged, and cursed and then asked polite again and some time in January this year, we just couldn't take any more of that bullshit and switched to php5. How hard was to migrate lots of messy code from php4 to php5? We did migration surprisingly fast and painless for many of our old projects. If you had error_reporting set to E_ALL durring development in php4, haven't used register_globals or magic quotes, you should be just fine. And we introduced new PHP5 OOP stuff to our new projects immediately. All in all, PHP5.2 is now what php4 had to be back then, and I am keeping my hopes high for PHP6.

  • September 6, 2007

    Some geeky statistics

    If you don't have a life anymore (like me), you will probably find these statistics/penetration reports interesting. :) Flash 9 is kicking, together with php5 and Apache. That's all I wanted to hear. Read on!

    Php5 finally gained some points, probably because Zend announced php4's end of life. That should happen years ago. :) Too bad Php6 release date isn't scheduled yet.

    Netcraft's last report says that Windows IIS takes 34.2% and Apache 48.4% of market share. Microsoft's recent gains raise the prospect that Windows may soon challenge Apache's leadership position. Apache has been the leading web server software since the March 1996 Netcraft Web Server Survey. In November 2005, Apache was found on 71 percent of web sites. It's worth noting that Apache has lost market share to another open source server, lighttpd (1.2% of all sites), and Google (4.4%) as well as Windows. But if Microsoft continues to gain share at its current pace, it could close the gap on Apache sometime in 2008.

  • April 25, 2007

    mysql + google

    A recent post on the Google Developer Blog announces some enhancements Google's made to MySQL, in hopes that they will be adopted in the next release, and to allow everyone to begin using them. At the moment, patches are available for mysql v4.x only. DO-h!

  • 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,

  • November 17, 2006

    Hiring Hobos To Wait in Line for PS3

    PS3 release in the States is delayed again, and mob is getting crazy! Some wait in lines, some pay homeless to wait for them, and some get killed in drive by waiting for PS3, including reporter. I never EVER had console, so I thought, it's time to get one. I will wait to see how Wii and PS3 will compare in the end.

  • October 28, 2006

    some notes on php design

    Today, I have read on metapundit.net some thoughts on how to improve php coding. Don't see the real point in this, except the faster coding. Readability and maintenance is degraded slightly.

    Update - 18.11.2006. - After taking some time to think about this, I have to agree with MetaPundit. Putting var names into array, and looping trough them makes code more maintainable. But I still have some issues with this, regarding more complex stuff.
    read more

  • October 20, 2006

    Filesystem corruption with PHP

    Writing to a file is easy with PHP. But what will happen if 2 processes try to write to a file at once? Exactly, your data might easily become corrupted and useless. You don't want that to happen, of course. That's why you need to implement file locking. flock() is your friend. For writing to a file, you want to obtain an exclusive lock on the file. There must never be concurrent writes to a file, after all. Here's an example.

    read more

  • June 20, 2006

    PHP Security – Never trust user input

    No mater if you are beginner or experienced PHP programmer, you should definitely check out PHP Security Guide by Rob Miller. SQL Injection, Spoofed Form Input, Cross-Site Request Forgery, File Uploads, Including Files, Register Globals, Magic Quotes… He is trying to keep it up to date, so please support him if you can.

    UPDATED 2.7.2006. - Here are some examples (PHP Security by Example).

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