. Editors Only: News Stories Pictures Gems Shortcuts Discuss Prefs Admin Bulletins Logoff Help

PHP Everywhere Home

Home    Bio   
  My Prefs   Sign Out
  John Lim is logged in.


Scripting in .NET is bullshit?
So what is the problem? Where is the procedural .NET!?! Where is the scripter's version of .NET!?! My colleagues are giving up on Microsoft after years of effort to consolidate on the MS platform. They do not want to be G. Andrew Duthie or Jesse Liberty. They want to create a few HTML pages with forms and write some procedural script on a server to process the data.

What I am starting to find are a number of PHP, Perl, and MySQL books appearing on the shelves of my coworkers. And they are not looking at Win2K or Win2003 as the platform or IIS as the server.

And please let's not waste time with the argument 'But you can basically script in .NET.' BS is all I can say to such a statement. -- Danny Boyd

tri: Also see Richard Tallent's response.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Merry Christmas and a Happy New Year
At this time of the year, there are better things to do than blogging. This is a time for serious fun. Love ya all!

PS: PHP5 beta 3 has just been announced.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Protein and Silicon Bugs
I'm currently sick, down with a protein bug. Not too much energy today, but after a nap, i felt energized enough to find a silicon bug in PHP5. Thanks to Jonas for the initial forensics.

Discuss (Join / Login first) Edit   permalink: #  

Innapropriate Abstractions: A Conversation with Anders Hejlsberg et al
The trouble with the wrong abstraction is there's no way out of it. In practice, though, it's very hard for class designers to make reasonable guesses about even the scenarios in which their designs will be used, much less the relative frequency of each kind of use. You may think your users will want transparency, because it lets them do really cool things, so you implement transparency. But if it turns out 99% of your users never care, guess what? Those people pay the tax. -- Eric Gunnerson

Lot's of good advice in this article. I see so many authors of PHP classes that try to do the right thing when the right thing to do is far from clear. To expect the correct design the first time is really really difficult. The key is don't try to be too ambitious. Use simple abstractions, so even if we screw up, it's easily fixed.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

.NET Rashomon Rudeness
One fact, multiple perspectives:

  .NET continues to surprise me. For example, we recently had to play a .WAV file on .NET. Luckily .NET allows you to call the underlying operating system to play the file. We really have the best of both worlds with .NET: platform and language portability, with hooks into the OS.

  .NET continues to surprise me. It still remains a thin layer between the OS and you. For example, we recently found out that playing a .WAV file in .NET requires making a Win32 call. It's frustrating that there is no .NET multimedia equivalent.

  .NET continues to surprise me. It still remains a thin hymen between the OS and you. Once you penetrate it, and do stuff like playing sexy music, you're no longer a virgin - you're hooked up to something better than .NET sex - the Win32 api.

Discuss (5 responses) (Join / Login first) Edit   permalink: #  

Andrew Stopford's the man for Rotor latte
Andrew Stopford wrote a book on PHP on Windows, but he's addicted to Rotor latte nowadays. He's sipping on hot .NET and CLR expresso on his blog. I read it to find out what's happening in the .NET world. Great brewing, Andrew!

Discuss (1 response) (Join / Login first) Edit   permalink: #  

The "Simple" Art of Code Design
I just visited SitePoint's Advanced PHP Forums, and spotted a debate on cache design. I only stumbled upon this because I saw that Manuel Lemos posted to this thread. Manuel has a unique way of writing that almost always guarantees a heated response. But Manuel brings up a good point. Most cache classes out there could do with better designs.

Now one good way of designing things is to define the parameters the code must work under in the beginning, then work your code from there. For example, for caching it could be:

  1. Works in multi-user environment and is portable. I'm also assuming in this design that we are saving to a file.
  2. Data must have a basic integrity checks. File IO can fail. Programs can crash.
  3. Solid concurrency and stress testing. Caching is typically most useful in overloaded environments.

Let's address these issues:

  1. Multi-user: You probably shouldn't be using PHP's file-locking, unless you're writing a private label class for only yourself. PHP's flock doesn't work on many systems such as NFS and FAT, so that's a big no-no. In adodb (and newer versions of smarty too i believe), content saving use the following file trickery:

    a. save contents into temporary file.
    b. delete the original cache file, eg. unlink($filename).
    c. rename the temporary file, eg. rename($tempname, $filename).

    A file rename operation is guaranteed to be atomic by the operating system, and is very efficient as file functions are always highly optimized.

  2. Data integrity: You should store and check the file-size in the cache file to ensure that the process didn't crash while saving. If you want stronger integrity, use crc32. In adodb, we store the file-size and use PHP's serialize function, which has many built-in integrity checks. Using serialize internally also means you can automatically save objects and arrays, not merely strings.

  3. Testing: I've seen elaborate unit tests for caching. But without the most basic concurrency test you might as well not do any testing.

    One such simple testing recipe is to write a script to continiously poll a cache file, saving occasionally. Output or log all errors (having a debug mode makes it straight-forward). Then execute the same script concurrently in separate processes and watch for problems. Let the testing cook for at least 10 minutes.

The above suggestions sound simple, but as I've learnt, simplicity is not easy to achieve. In youth, everything is oversimplified or too complicated - real simplicity comes from experience. Unfortunately, it's only when we get too old and senile that everything becomes truly simple ;-)

Discuss (7 responses) (Join / Login first) Edit   permalink: #  

It takes a snake to prove that .NET is fast for scripting
Some language experts have said publicly that scripting languages built on .NET or Java bytecodes will always perform poorly due to limitations in bytecode design.

Jim Hugunin, contrarian to the core, has posted an email which suggests the reverse, by comparing Python written in C (CPython) with one Jim wrote using .NET (IronPython). Jim is the original author of Jython, the Java implementation of Python, so he has the skills to back his claim.

And if his claim is correct, I think that the push to move scripting languages (eg. PHP) to Parrot or similar bytecode systems which can be Just-In-Time compiled will accelerate. The downside is that the overhead of dynamic eval's is much higher - making scripts that use eval() to dynamically compile code prohibitively expensive.

Discuss (Join / Login first) Edit   permalink: #  

Zend/Win Enabler - Running PHP on Windows
I've been advocating FastCGI as the most stable way to run PHP on Windows for a long time. Now I see Zend has decided to commercialize such a FastCGI solution.

Open source is an extremely incestous activity. Everyone works together and competes together (I just hope they don't sleep together). The FastCGI work was done by an Shane Caraveo, who works for ActiveState, a company that sells products that directly competes with Zend. And in the fine tradition of open source, there is always a free solution when you don't want to pay anything - you can use the free FastCGI+PHP installer for Windows I wrote a while back.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Study Questions Companies' Ability to Handle J2EE
I'm back from my holidays, and am continuing to dive into Java. I'm trying out Eclipse, been using JBoss and am reading Thinking in Java.

Java remains an excellent replacement to coding in C or C++. But for many domains, Java is too complex and an overkill. Here's a recent study that supports this view:

Wily Technology, a Brisbane, Calif. company that gauges how well Java performs, said it has completed a study on the quality of how Java 2 Platform, Enterprise Edition (J2EE) applications run in certain enterprise environments.

After interviewing more than 350 J2EE users who work outside the software industry, the research firm concluded that applications running on the J2EE platform were available to users 88 percent of the time. "That means on average, companies are losing over 20 hours, or one full day per week, of availability," said Lewis Cirne, founder and chief technology officer of Wily Technology.

The Wiley study found that enterprises who rely on J2EE to run their applications must endure at least one full day of downtime per week. Downtime, a reviled word in the computing industry, could mean lost dollars for companies that rely on software to power their businesses.

Discuss (5 responses) (Join / Login first) Edit   permalink: #  

The Mans Aways on Holidays
Back in 2 weeks time, hopefully sane, zesty and healthy. And to all you Malaysians - a happy Raya holidays!

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

PHP Benchmark
Sebastian is doing some neat work on testing performance. I found it hard to decipher the data, so I graphed it in Excel.

PHP Sebastian Benchmark:

There seems to be some drop-off in performance in PHP 4.3.4. I guess the core developers are putting their energies into PHP 5.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

21st Century Blues
I guess i've finally arrived in the 21st century and it feels good. I have submitted to the onslaught of new technology and just bought an Apple iPod. I liked it so much that i bought it even though i wasn't sure whether i had a firewire connection on my windows notebook. Luckily it did, or i would have felt really stupid.

Discuss (Join / Login first) Edit   permalink: #  

ProFont for Windows and X-Windows
I remember one of my programming colleagues (Rajesh, a very talented coder, at that time just fresh from college) many years ago placing newlines after every line of code, using a lot of white space, making his source code look very artistic. I pointed out to him that when you can only see 10 lines of code on one screen, you need to scroll up and down all the time, and it takes a very long time to understand what's going on.

My advice to him was to chunk his code, making each dense chunk represent some complex computation, and to to make each chunk fit one screen. I also gave him a second piece of advice. It was related to fonts: avoid Courier - use a professional font where zero's are slashed, and 1 and l are distinguishable (that's one and letter L).

That's where ProFont comes in. It's a great programming font for the Apple Macintosh, designed to look good in small font sizes. I remember using ProFont religiously on my Mac for software development many years ago, and looking for something similar when I moved to Windows. Recently I found that it has been ported to Windows (and X-Windows too). If you want to a panoramic view of your code, but you don't want to go blind, this is the solution - highly recommended.

PS: Use the .FON version. It's better optimized for small sizes than the .TTF one.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

PEAR2: The interface is the framework
PEAR1 is now suffering from the fact that it focused from a long period of building technical foundations without planning the community growth at the same time. -- Lukas Smith.

Now that the cat is out of the bag about PEAR's problems, I will give my 2 cents worth.

Firstly, I want to say that I am a PEAR user, but not a PEAR developer. I do use code from PEAR, everyday. There is some first class code in there. But yes I do see problems, and I also have a radical solution at the very end of this essay.

The biggest problem IMHO with PEAR is the arbitrary way things are apparently run. Why is one class accepted, and another rejected? If it is because they do the same thing, then why are there so many classes that do the same thing in PEAR?

My perception is that

  • there is no planning except for flavour of the day
  • there are egos in the community, so people introduce new classes rather than rewrite existing ones to add new functionality
  • poor design in some of the original classes makes it impractical to extend the original classes
  • the quality of PEAR is uneven, brilliant gems combined with duds - and the problem is that the duds begin with the base classes (PEAR and PEAR_Error)

How can things improve? Obviously PEAR2 must be designed to grow with the community. One way to grow in an open source world (if there is no leader with the stature of Linus in the community) is to give everyone a chance to contribute their own code fairly, without the arbitrariness that we see today.

In the Perl world, we have CPAN, where there is no thought police telling you that your code is not acceptable - you just register as a developer, declare a namespace, and upload. Yes there is lots of code duplication, and yes there is no coding standard - but i do perceive that it is fair.

I have a suggestion for PEAR. I think they need to be more open, and allow multiple people to develop similar classes for the same category. What the PEAR group could do is standardize the API's for specific categories. This API defines a minimum inter-operatable subset of code for a specific category. Poor documentation will be less of an issue if all contributed code share a common base API.

I can see some similar classes in PEAR share common APIs informally, but it would be better if it were standardized, so it is less arbitrary and more inclusive. In fact, PHP5 has a good way of enforcing this contract with the implements keyword. The launch of PHP5 is also a good time to start, because we can finally put PEAR exceptions to sleep and use built-in exceptions.

Now here comes the really radical suggestion - if your contributed class conforms to that category's unit tests, it should be accepted into PEAR. No ifs, no buts, no thought police. And how would you pick which class to use if there are 10 implementations? Let the PHP community decide! Votes or download statistics could be displayed to "fairly" quantify the best code contribution for a category.

Lastly, I want to remind everyone that standardizing on a common API does not inhibit creativity, provided that the API is sensibly chosen. For example, ADOdb and MDB both have a PEAR DB emulation layer. In fact common APIs do encourage innovation within a shared framework (eg. the BSD forks go in different directions but share code).

Thanks for listening.

Discuss (23 responses) (Join / Login first) Edit   permalink: #  

Today I ran JBoss for the first time
Another personal milestone i just wanted to note before i forget.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

Smash the Windows
As our society becomes ever more dependent on information technology, the gulf between those who understand computers and those who don't will get wider and wider. In 50 years, perhaps much less, the ability to read and write code will be as essential for professionals of every stripe as the ability to read and write a human language is today. If your children's children can't speak the language of the machines, they will have to get a manual job - if there are any left -- Dylan Evans.

Discuss (6 responses) (Join / Login first) Edit   permalink: #  

A Turning point for PEAR?
A posting in the php.pear.dev newsgroup by one of PEAR's leading developers. I think this is a very honest assessment, and I'm hopeful about this.
> From: Xavier Noguer [mailto:xnoguer#xavier-noguer.com]
> Sent: Saturday, November 08, 2003 3:41 PM
> Martin Jansen <mj#php.net> escribió
> > (http://pear.php.net/manual/en/developers.contributing.php)
> >
> > It is pretty funny to see how much developers have actually read the
> > "Developers Guide" ...
>  I've read that guide. I just don't seem to be able to take it seriously
> when
> it lists requirements that have never, as far as I know, been voted by the
> pear group or the developer community at large, such as regressions tests
> (http://cvs.php.net/diff.php/peardoc/en/guide/developers/contributing.xml?
> r1=1.8&r2=1.9&ty=h)

I agree here. While previous mistakes don't make a wrong a right, I think our whole manual lacks any consistent concept of what we really feel needs to happen when and where.

Anyways we have a bunch of messes that are a result of the long period of limited peer review, followed by a period of package inflation, followed by the today ruling confusion.

I think its time we fix our standards by starting from a clean slate with a PEAR2. There we can think about how to best deal with our developer and users base and how to great the best possible code in a PHP version which actually supports our needs for OOP.

PEAR1 should of course be maintained as we all have an interest to keep that code running and to use PEAR1 as a momentum towards a PEAR2 which build on the past experience.

<rant> PEAR1 is now suffering from the fact that it focused from a long period of building technical foundations without planning the community growth at the same time. This has lead to numerous problems and is making us very inefficient. Of course PEAR1 has a lot to offer, but I don't think we are scaling well and past mistakes seem to haunt us more and more, which we don't seem to be able to fix. So I think we need to recognize our past which we of course need to maintain to remain credible, but at the same time we should work to build a more scalable PEAR2 in which we can address our issues on a clean slate. </rant>

> Would you be so kind to point me to the pear group document or public > discussion in which this requirement was approved?

There is no such decision I can remember. As George pointed out we discussed this point in Amsterdam, however I don't remember that anyone decided on requiring documentation at first commit. However our decisions there were mostly only concepts and not complete. Anyways maybe someone should check when this was commited anyways.

Regards, Lukas Smith

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

Is Novell-SuSE deal a brilliant Big Blue power play?
Perhaps the most interesting take on the Novell-SuSE deal is the above link. What has been missed by other commentators is that this is a tri-partite agreement with IBM. David Berlind clarifies a lot of things, even if it is still not the full picture.

Red Hat is also not standing still, abandoning its hobbyist roots to sell only to Enterprises. As Bruce Perens says, "The open source community is supposed to produce Fedora so Red Hat can put a stamp on it and charge lots of money for it."

Does anyone have any recommendations for free Linux distros? Ease of installation and use are more important to me than power (hey, the first computer i ever bought was a Mac.)

PS: Björn Schotte has some groovy pictures of the recent PHP Conference 2003 in Germany.

Discuss (9 responses) (Join / Login first) Edit   permalink: #  

ADOdb 4.02 released with PHP5 suppport
Been playing around with PHP5. ADOdb 4.02 now works transparently with both PHP4 and PHP5. If PHP5 is detected then the following features will be automatically enabled:

Support for PHP5 iterator overloading

  $rs = $DB->Execute("select * from table");
foreach($rs as $row => $fields) { var_dump($fields); }

Support for PHP5 exceptions

Just include adodb-exceptions.inc.php and you can now catch exceptions on connection and execute errors as they occur.

try { 
	$db = NewADOConnection("oci8"); 
} catch (exception $e) { 

I managed to surprise myself, the PHP5 iterator code is backward compatible with PHP4, even though the IMPLEMENTS keyword is illegal in PHP4, thanks to the magic of includes.

And IMHO, the PHP5 iterator implementation with IteratorAggregate and Iterator, though powerful, is too complicated - certainly not in the spirit of PHP.

Discuss (7 responses) (Join / Login first) Edit   permalink: #  

PHP 4.3.4
After a lengthy QA process, PHP 4.3.4 is finally out! This is a medium size maintenance release, with a fair number of bug fixes. All users are encouraged to upgrade to 4.3.4.

Bugfix release
PHP 4.3.4 contains, among others, following important fixes, additions and improvements:

Fixed disk_total_space() and disk_free_space() under FreeBSD.
Fixed FastCGI being unable to bind to a specific IP.
Fixed several bugs in mail() implementation on win32.
Fixed crashes in a number of functions.
Fixed compile failure on MacOSX 10.3 Panther.
Over 60 various bug fixes!

The bug-fix that most concerns me most is this one:

Fixed bug 25404 (ext/pgsql: open transactions not closed when script ends).

In our early days with PHP, we used MySQL a lot. Nowadays, most of our PHP work is with PostgreSQL and Oracle (with the occasional MSSQL project). MySQL is still a good database, but without triggers and views, it no longer meets our company's needs.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

Sun, Zend integrate PHP with Sun's Web server
Zend, oversees the development of PHP and also sells a commercial implementation of the technology. On Monday it released two products that integrate with Version 6.1 of Sun's Java System Web Server, allowing companies to deploy PHP on Sun's software. (The Java System Web Server was known previously as the Sun ONE Web Server.)

The two products are the PHP Enabler, which is intended to let PHP programs run smoothly on Sun's Web server, and the Zend Performance Suite, which uses code acceleration, content caching and other software tricks to improve the performance of PHP on the Sun platform, the companies said.

Discuss (Join / Login first) Edit   permalink: #  

Icky Sticky Leaky PHPloat
After running PHP5 beta 2 for 2 days on Apache 1.3 (multi-threaded SAPI on Windows), I was surprised to find that the process was taking 500 Mb. There must be lots of memory leaks. I'm pretty happy that most PHP code just runs, but obviously it's not production ready.

Now the hard work starts, how to integrate new PHP5 functionality without impacting old PHP4 code. After thinking a while, I realize there are only a few things I can do to write portable code:

  • In PHP5, we use __clone() to duplicate objects. To make this portable, simply check the PHP_VERSION:
      $obj2 = (PHP_VERSION >= 5) ? $this->__clone() : $this;
  • Error-handling can be encapsulated in a separate function, and conditionally included based on PHP version. Eg.
    if (PHP_VERSION >= 5) include("exceptions.inc.php");
    else include("error.inc.php");

Unfortunately, most other features require explicit use of keywords that are illegal in PHP4, eg. private, protected, implements, etc. These require maintaining a separate codebase for both versions of PHP, or some special pre-processing to be done on the code depending on the versions. Does anyone have a better suggestion?

PS: I will be releasing a new version of ADOdb soon, one that should be compatible with PHP5.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

PHP 5 beta 2 is out
Just downloaded the Windows install and tested it.

To run on Apache, I copied php4apache.dll to the php5 root directory, and modified Apache's httpd.conf:

LoadModule php5_module c:/php5/php5b2/php4apache.dll
AddModule mod_php5.c
AddType application/x-httpd-php .php

For some reason, php_mysql.dll is not working. The error message is "The procedure entry point mysql_create_db could not be located in the dynamic link library LIBMYSQL.dll". I made sure that the LIBMYSQL.dll was the one that came with the PHP release. I'm using MySQL 4.0.12. Perhaps someone can comment on this.

However Oracle's oci8 extension is working fine. As most of our software runs on Oracle, it was easy for us to continue testing PHP5. 99% of all code ran fine. The only gotcha i found was that if your function returns a reference, you can no longer do this:

  return $this->function();

but have to change your code to this:

  $ret =& $this->function(); # & is not needed if you don't support PHP4
return $ret;

A very impressive beta release except for the above glitches.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

A different take on PHP-Con
Before I came down I was worried about how I would be accepted by this crowd as a Microsoft representative. Would it be hostile? Would it be open?

Discuss (Join / Login first) Edit   permalink: #  

Living La Vida Longhorn
Chris Sells kicks off his inaugural installment of the Longhorn Foghorn column by defining the pillars of "Longhorn," the next generation of the Windows operating system, and providing an overview of each pillar.

Also see Working with Data in ASP.NET Whidbey for an overview of the next version of ASP.NET.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Is Pharrot That Fast?
I have not seen the sources of the Pharrot compiler, but if it is just a proof of concept, it is not likely that much error-checking is done. I expect the figures for Pharrot below to increase by at least 50% when all the error-handling is put in.

The figures are still very impressive despite these reservations.

Generating a Mandelbrot fractal
 – PHP,                     2.4  seconds
 – PHP-Hacked,              1.2  seconds
 – Parrot without JIT,      0.5  seconds x1.5 = .75
 – Parrot with JIT (Intel), 0.08 seconds x1.5 = .12

tri: This is the best Parrot reference, next to the source of course.

Discuss (Join / Login first) Edit   permalink: #  

The Shape of Pharrots to Come
John Coggeshall mentions that the PHP on Parrot project has been named "Pharrot" by the php-con conference attendees.

Here's my take on things. Now I don't have any inside info, so the following is entirely guesswork, and any resemblence to reality is entirely your imagination:

  • Although Sterling and Thies are very modest, given the fact that they were given the closing keynote and the amazing performance improvements - Pharrot will probably be PHP 6.

  • The speed of the JIT means that PHP will become a general programming language. A high performance application server written 100% in PHP becomes practical. A high performance anything becomes practical in PHP.

  • The tribes using Parrot will probably include Python, PHP and Perl. Code sharing between different programming tribes will become a reality. This does not mean that there will be full interoperatability between all languages, because (a) there is no common runtime library (yet), (b) and no consensus on what will be the default PMC's (Parrot's language extensions) installed.

  • There will be battles fought over the run-time. In PHP4/5, after execution, we throw away the opcodes together with the bath water, or store them in shared memory. Parrot gives you more choices. See the end of Dan Sugalski's Parrot internals presentation (ppt).

  • The Zend API is dead - big deal. Parrot is a big opportunity for companies with skill and resolve. The tools market for open source programming languages suddenly becomes much larger because you are able to support so many more languages effectively.

  • My prediction: the first beta of Pharrot will be out in 2006.

PS: Selkirk was prescient about parrot. Smart chap.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

PHP & Parrot (PDF)
Here is the PHP-Con Closing Keynote by Sterling Hughes and Thies Arntzen on running PHP on Parrot.

Parrot is a virtual machine used to efficiently execute bytecode for interpreted languages. Parrot will be the target platform to which Perl 6 code is compiled.

From their slides:

       Parrot is FAST!

Generating a Mandelbrot fractal – PHP, 2.4 seconds – PHP-Hacked, 1.2 seconds – Parrot without JIT, 0.5 seconds – Parrot with JIT (Intel), 0.08 seconds

I presume that PHP-Hacked is the patched PHP that Sterling and Thies released in August. I have been a sceptic about Perl 6 because it has taken so long, but this is impressive stuff.

Discuss (5 responses) (Join / Login first) Edit   permalink: #  

Natural Born Killers of PHP
Recently I revised Optimizing PHP, an article that I wrote in 2002. I'm pleased to say that it hasn't aged much. The changes I had to make include a recommendation to use FastCGI with IIS, adding Turck MMCache to the opcode cache list, recommending Cache_Lite, replacing foreach with list/each for large arrays, and the realisation that arrays need to be passed by reference too.

Then I realized how much more I could have discussed. I started to think more about performance profiling after discussing APD in a previous post.

Now there is some logic to the fact that functions with many lines of code will run slower than ones which are short and brief. However sometimes it's the shortest code snippet that cause the real slowdowns. That's because these code snippets call external functions that hide a lot of complexity behind a deceptively simple and light exterior. With any of the following natural born killers, one thoughtless line of code can result in a unbearable x100 times slowdown:

  • SQL statements - for example, forgetting to add an index to a large table will have a massive impact on performance.

  • Regular expressions - because regular expressions work by back-tracking when a match fails, its common for a regular expression to be exponentially expensive to compute. The longer the string, the worse it becomes.

  • Network calls - the increasing popularity of SOAP and similar inefficient but easy-to-use protocols open up new vistas of unscalability for the unwary.

Classic performance tuning techniques used by XDebug and APD give you a summary of all functions with long execution times. This is useful, but we need tools to easily pinpoint, measure and tune the overhead of killers such as SQL statements, regular expressions and RPC calls. I think that we already have enough Open Source CMS projects out there. Tuning tools like this are great idea for students and developers with time to kill, looking for an interesting Open Source project to start.

Discuss (7 responses) (Join / Login first) Edit   permalink: #  

PHP Performance Profiling with APD
Good article on profiling PHP using APD, the Advanced PHP Debugger. This is a bit of a misnomer, because APD is not a debugger you use to step through your code, but is actually a diagnostic and profiling tool. I mostly use XDebug for profiling, but APD looks like a cool alternative.

And if you are interested in performance tuning, do have a look at ADOdb's database performance monitoring features. The dreadful thing about SQL is that it is an iceberg of complexity hidden in a deceptively simple query language. Bad PHP code can slow your code down by a factor of x2-5 perhaps. But one bad SQL statement can cause a x10-100 times slowdown.

Lastly, if you are using Windows, unless you have the ability and means to compile APD, you're out of luck. This is one area where PECL (which is the official repository for PHP extensions) could improve on.

Update: George (APD's author) mentions that Shane Caraveo has ported APD to Windows, and Will and John add that pre-compiled PECL dll's for Windows are available from here and there. (added 25 Oct 2003).

Discuss (5 responses) (Join / Login first) Edit   permalink: #  

PHP Compiler Cache Internals
The latest English issue of PHP Magazine has an interesting article about implementing a PHP Opcode Cache by George Schlossnagle, the author of APC.

If you're familiar with the English expression, don't throw the baby out with the bath water, then you will be amused to learn that that's exactly how the Zend Engine (PHP's compiler) works. It will compile the PHP into opcodes for a page request, and throw the opcodes away immediately after the code completes.

This may sound really wierd and inefficient, but of course Zeev and Andi would not have been able to start their own company, Zend, without a business plan that involved fixing this "stupidity". And you thought Microsoft was evil ;-)

Now it is perfectly normal when developing a platform to leave gaps for commercial vendors to fill. That creates a ecosystem where we have companies willing to pay to maintain and promote PHP. So this isn't meant to be an attack against Zend, but an acknowledgement of business realities.

This omission of the Zend Engine stimulated interest in several open source developers to create their own opcode caches. APC is one of the earliest open source opcode caches.

In my benchmarks (yes, you see me benchmark a lot, because that's the only way to understand the performance profile of PHP software without spending a lot of time examining source code) I noticed that the overhead of PHP opcode caches was less for small scripts. Obviously there is some copying of instructions from the cache in shared memory during script execution. The question was how much? How did it affect performance?

Now we have the answer. George says restoration of the opcode info for script execution "involves only a so-called shallow copy of the op_array. A shallow copy means that only the structure itself is copied, but none of the elements it contains pointers to."

This means that the actual opcodes are not actually copied, only the pointers to the structures that contain the opcodes. Apart from that, the function and class metadata and any static variables are restored, and the inheritance hierarchy is dynamically resolved.

So the overhead of the opcode cache is O(n), where n is the number of functions+classes+inheritance levels+properties+PHP files. It is not proportional to the number of lines of code - that would be as worrying as throwing the baby with the bath water.

Another excellent issue of PHP Magazine!

Discuss (Join / Login first) Edit   permalink: #  

ADOdb 4.00 released
ADOdb 4.00 is out after a 3 month beta testing process.

The distinguishing feature of this release is the performance monitoring functionality. AFAIK, it is the first Open Source cross-platform, multi-database performance monitoring and health check software in the world.

It features:

  • A quick health check of your database server using $perf->HealthCheck() or $perf->HealthCheckCLI().
  • User interface for performance monitoring, $perf->UI(). This UI displays:
    • the health check,
    • all SQL logged and their query plans,
    • a list of all tables in the current database
    • an interface to continiously poll the server for key performance indicators such as CPU, Hit Ratio, Disk I/O
  • Gives you an API to build database monitoring tools for a server farm, for example calling $perf->DBParameter('data cache hit ratio') returns this very important statistic in a database independant manner.

ADOdb also has the ability to log all SQL executed, using ADOdb's LogSQL feature. All SQL logged can be analyzed through the performance monitor user interface. In the View SQL mode, we categorize the SQL into 3 types:

  • Suspicious SQL: queries with high average execution times, and are potential candidates for rewriting
  • Expensive SQL: queries with high total execution times (#executions * avg execution time). Optimizing these queries will reduce your database server load.
  • Invalid SQL: queries that generate errors.

Each query is hyperlinked to a description of the query plan, and every PHP script that executed that query is also shown.

Databases that work with the performance monitoring features include MySQL, PostgreSQL, Oracle, Informix, MSSQL, DB2. Code contributions are very welcome.

Download: http://php.weblogs.com/adodb#downloads
Performance Monitoring Docs: http://phplens.com/lens/adodb/docs-perf.htm

Discuss (Join / Login first) Edit   permalink: #  

PHP EasyWindows Installer released
The latest release of this installer, which sets up PHP 4.3.3, FastCGI, Turck MMCache 2.4.1, PEAR and ADOdb for IIS, Apache 1.3 and 2.0. This is the installer that we use in-house for our Windows projects.

My recent benchmarks with PHP to test XML-RPC performance show that IIS is the fastest PHP web server on Windows. The XML-RPC benchmark was a PHP script with 1 select, 2 update queries to Oracle.

Apache 1.3    44         
Apache 2.0    42         
IIS+FastCGI  108        
If you want a PHP installer that is tuned for IIS with FastCGI, this is the one.

Formerly, the version numbers of the installer were not synchronized with PHP. Now the numbering system will match the PHP version for easy tracking.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

The Philosophy of PHP
Every couple of months, someone requests the Perl style regular expression operator (=~) be implemented for PHP. The PHP internals group response to this is a good insight into their clarity-first design style:
I don't think there's a chance we'd agree to implement such regex operators (wether the singular or plural versions :) Except for it pushing PHP in Perl's direction of being unreadable it doesn't really give any added value. I don't see how it is a significant improvement over using a function such as preg_match(). (Actually I think the latter is more readable).

Here's a small quote from Mr. Ritchie: "A language that doesn't have everything is actually easier to program in than some that do."

I think Perl is a prime example of why the quote is correct. -- Andi Gutmans

You are pushing towards


This is not human-readable code and one of the basic characteristics that sets PHP apart from Perl. Every non-trivial line of PHP code has a decypherable keyword that you can plug into the manual to figure out what that line is doing. We make sure of this by keeping the number of operators to a minimum. As for your bitshifting example. It has nothing to do with the frequency of use, it has to do with readability. -- Rasmus

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

We need barking dogs to fix "The PHP Scalability Myth"
This above link is a great article, but you must be an asphyxiating ostrich burrowed in the sand to say that PHP doesn't scale. It's not that slow a programming language, it has few bottlenecks, and perhaps most important - there are many case studies of large web sites using it for mission critical work (eg. Lufthansa's online booking and Yahoo).

However I do feel something is still missing from PHP. Not in the language per se, but in the conceptual overview. What we really need are dogs barking and cats meowing in our very own virtual Pet Shop. For people who don't understand this reference, the Pet Shop is famous web application created to demonstrate best practices in scalability and software design for J2EE and .NET.

In contrast, there is no reference PHP Pet Shop, and no accepted and well-documented methodology on how to create scalable web-sites with PHP. So you need to be very smart, or get the advice of technical gurus to keep everything scalable and running smoothly. It's no accident that Yahoo, perhaps the biggest web-site that has invested heavily in PHP, employs so many cool cats who have a deep knowledge of PHP such as Rasmus and Andrei.

Update: Slashdot discusses this article. I liked this comment best:

The sad reality is that so few developers know enough to fully exploit J2EE that they wind up doing little more than what PHP does better in the first place.

True wisdom is knowing your limitations (18 Oct 2003).

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

10,000 ways to Ni Hao with Unicode and PHP
Joel Spolsky has been cursing the lack of support for Unicode in PHP. So last week, he wrote this great article on The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!).

Of course, that still doesn't answer his initial question of how to get Unicode working with PHP. Well Scott Reynen had the solution and wrote How to develop multilingual, Unicode applications with PHP in response to Joel's frustration.

Scott's technique works on all versions of PHP. Or you can just use the UTF8 character set and mbstring functions, which should run faster as they are coded in C. To use mbstring, you need PHP 4.3 or later (it was buggy pre-4.3). On Unix, you will need to compile the extension in. On Windows, you just need to modify your php.ini.

Update: l0t3k is working on a Unicode I18N extension based on IBM's open source International Components for Unicode. The extension includes a UnicodeString class with the requisite searching, replacing, casing, trimming, and classification methods. Get the CVS version (16 Oct 2003).

PS: Ni Hao means hello in Chinese.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

Oracle ramping up its support for PHP?
Recently, Christopher Jones from Oracle Australia emailed me, asking me a few questions about ADOdb. Apparently Oracle is looking into ramping up its PHP support, and are starting to study what PHP developers are actually using to connect to Oracle databases.

It was a pleasant surprise to find out that he was 1 year behind me at the University of Melbourne, Australia. We never met, but probably passed each other in the dingy computer labs. Ah, youth - I was quite a skinny scruffy lad, and 22 kilos lighter too (50 lbs).

And for those of you who are having problems with Oracle and PHP, this forum at Oracle can be used to ask PHP questions. The nice thing about this forum is that you don't need to get an expensive metalink account (Oracle's support site) to get answers from real experts.

A quick dig through the forums revealed some useful nuggets of information that I didn't know, such as this guide on using DBMS_OUTPUT with PHP. DBMS_OUTPUT is Oracle's equivalent of echo.

Discuss (Join / Login first) Edit   permalink: #  

Bridging PHP and .NET with XML-RPC
A couple of months ago, I mentioned that we are developing rich Windows clients running on .NET. We are still using PHP on the web server, and using XML-RPC for communication between .NET and PHP. We could have tried to use SOAP, but at that time there were too many deficiencies in NuSOAP's support of arrays and collections.

We used the following XML-RPC libraries: Keith Deven's for PHP, and the Cook Computing library for .NET. It turned out to be very simple to get everything working. The docs were clear, and with half a day of coding, we got basic connectivity up.

We've been happy using Keith Deven's PHP library, but recently we decided to test using the epinions xmlrpc extension that comes bundled with PHP. We thought it would be significantly faster as it was coded in C. To our surprise, it made very little difference to performance. The improvement in speed was just 1%. The reason is simple: most of the overhead is in the networking, apache processing, and actual computation. The breakdown of time is roughly:

  • 10% testing overhead
  • 50% networking/apache overhead
  • 40% PHP computation (1 query and 2 updates to Oracle)

Given that the client/server testing was done on a single machine, that 50% networking/apache overhead is quite high. This explains my interest in Nanoweb and simpler alternatives.

Update: On Windows, it appears IIS is still the high performance solution. Apache 2.0.46 and 1.3.28 did not exhibit good performance (with PHP running as a SAPI). But with IIS 5 running FastCGI, the networking/IIS overhead drops to about 10-15%.

In my tests, I was pounding the web server with 100 simulated clients, and I suspect that there are still some internal bottlenecks crippling PHP performance as a threaded Apache SAPI (either in the threads support or oci8 extension). I think that Apache with FastCGI would perform better, but I don't have the time to test this.

Discuss (7 responses) (Join / Login first) Edit   permalink: #  

Twisting by the PHPool
Recently I posted a link to Twisted, a python library for developing socket servers. This generated a storm of interest as to whether PHP is suitable for developing similar custom networking applications. You should read the commentary in the above link for some interesting remarks by BDKR.

So i benchmarked Nanoweb, a webserver written in PHP, against Apache. Test was repeatedly requesting a 4K HTML file (adodb-session.htm), using M'soft's WAST set at 10 concurrent threads. All software running on a 2.6 Ghz Win XP machine. PHP-CLI 4.3.3 was used to run Nanoweb.

Nanoweb          176
Apache 1.3.28    300
These figures suggest that a PHP networking app (Nanoweb) running on brand-new 2003 hardware (3 Ghz PC) will be faster than a program written in C (Apache) on good year 2000 hardware (1Ghz PC).

Now if someone had told me in 2000 that in 3 years I would be able to run a web server written in PHP, and that it would run faster than the Apache of the year 2000, I wouldn't have believed the person. I think this sort of performance is a fantastic achievement for PHP and its developers.

PS: For those of you who read the Twisted docs, you will see that it does not use threads, but callbacks. It should be possible to do something similar in PHP too.

New: If you click on Discuss, you will see that Kemar has posted some benchmarks on Linux, and the numbers are quite different from Windows XP (9 Oct 2003)

Discuss (14 responses) (Join / Login first) Edit   permalink: #  

SAP interface to PHP
Recently we had a need to interface to SAP. To my pleasant surprise, there is a PHP extension that does this...

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

php-con West extends Early Bird to Oct. 10th!
Oops. Here's another announcement that slipped through the cracks while i was sick. Sorry Monica.

php-con West 2003's early bird deadline has been extended till Friday, October 10th. It's not too late to sign up tutorial, technical session or full conference packages at reduced fees. Register online at http://www.php-con.com/ or download and fax one of our registration PDFs.

** Additional Savings and Special Promotions **

Do you work for a non-profit or university? Are you a student or a member of a PHP user group? You may be eligible for additional savings on registration fees.

* Students get 50% off registration when they include a current class schedule and photo ID with their faxed registration

* Employees of Yahoo!, Universities and Non-Profits can take an additional 10% off rates.

* Members of recognized PHP User Groups, phpclasses.org and PostNuke are also eligible for additional savings.

Want to find out if you qualify? Email monica#php-con.com for more information.

Discuss (Join / Login first) Edit   permalink: #  

Tiki Wiki still enjoying phenomenal growth
Last week I got this email from Marc Laporte, informing me that Tiki Wiki has decided to switch to ADOdb as the database portability layer. I was sick at the time and have only just posted it. The statistics on Tiki Wiki are certainly impressive.

#4 most active project on Sourceforge

#5 best rated app on Freshmeat.

111 developers on SourceForge:

1300+ members on

July 2003 Project of the Month on Sourceforge

350 pages of fully illustrated documentation for Tiki 1.6

1.7 doc is in progress. Here is a list of "undocumented features":

An idea of what's ahead:

Here are our current partners:

Here are future partners:

Tiki Wiki Discussion on database abstraction:

I believe that Tiki Wiki was formerly using PEAR DB. For people who are using PEAR DB and believe that switching to ADOdb is hard, they couldn't be more wrong! ADOdb has a PEAR DB emulation layer that is quite complete. I have ported PEAR DB applications by changing include files to ADOdb and they worked straight off.

Marc also mentions that they are looking for PHP and Java developers who would like to contribute to the project. Guys, keep up the good work!

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Getting Twisted
Twisted is a framework, written in Python, for writing networked applications. It includes implementations of a number of commonly used network services such as a web server, an IRC chat server, a mail server, a relational database interface and an object broker. Developers can build applications using all of these services as well as custom services that they write themselves. Twisted also includes a user authentication system that controls access to services and provides services with user context information to implement their own security models.

This is certainly one area where PHP is lacking. Twisted looks really nice for developing specialized network servers.

PS: Also see David Mertz's multi-part tutorial on Twisted.

Discuss (5 responses) (Join / Login first) Edit   permalink: #  

Tuning PHP Database Performance
In a typical web application, most of the time is spent querying the database, formatting the results and spitting the html back to the browser. This also means one of the biggest speed bottlenecks are your SQL queries.

I became interested in db tuning tools after using the excellent 3rd party Oracle development tool TOAD which has similar functionality. We have a team of PHP developers who use Oracle, and without a tool like TOAD, it would be impossible to identify bad SQL and database bottlenecks quickly. As our clients use a wide range of databases, I felt that a similar tuning tool that works across multiple databases would be useful. And to my surprise, popular tools such as PgAdmin, PHPMyAdmin and the like do not have equivalent functionality.

That is why the latest feature of ADOdb (download here) is performance monitoring. This allows you to log all SQL executed into a table called adodb_logsql (sometimes when it comes to naming, not being original is a virtue), together with the execution time and the name of the script that called it. This logging is done by calling


ADOdb also provides tools to analyze bottlenecks in your SQL. After logging your SQL, ADOdb then classifies your SQL into

  • Suspicious SQL, which is SQL with high average execution times. It is suspicious because the SQL might be poorly written. Tuning these SQL will improve the response times of your web application.

  • Expensive SQL, which is SQL with high total execution times (eg. average execution time * # times executed). Tuning these SQL will drop the load on your database server.

  • Invalid SQL, which is SQL that generates error messages.

We provide a HTML UI, which you can invoke with:

$db = NewADOConnection('mysql'); # driver
$perf = NewPerfMonitor($db);
Click on "View SQL", you will see your queries nicely classified. Clicking on an SQL query will bring up a new window that explains the execution plan, and lists which the PHP scripts that call this SQL.

You can also control the number of SQL queries to view by entering a number in the input field at the top-right of the View SQL screen.

Field Test

This week I had my first successful field test of the system on a customer site. I have tuned several in-house systems already, but this was my first opportunity to test this on a system where I was not familiar with the code.

After gathering the statistics for half-an-hour, we opened the performance UI. Of course performance is relative: a query that returns 100,000 rows and takes 1 second is pretty fast, but any query that takes 0.1 seconds to retrieving one record is pretty slow.

We found several statements that process less than 10 records but were taking over a second to execute. A quick check revealed that the table in question was not properly indexed. After indexing, we saw a 1000% improvement in performance for those queries. Also some queries were pulling whole tables with thousands of rows from the database and performing joins in PHP; a simple query rewrite solved this.

We found all these problems within the first hour of using the new performance monitor. Before I had this tool, I would have had to interview the end-users on what pages were slow, manually benchmark the pages to check the response times, and then read the source code to try to identify the bottlenecks. This new feature saved me days of tuning! Good job, if i do say so myself.

PS: Thx for all the nice messages while I was sick.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

Busy Sick Bumblebee
Busy with work pressures and sick (stomach bacterial infection) this week. Let the miserable rest.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

PHP Component Model (PCOM) Wiki
Wow, Sebastian has put up a Wiki for his proposed PHP Component model. Feel free to join in.

Discuss (Join / Login first) Edit   permalink: #  

Cyberinsecurity: The Cost of Monopoly
Technology analyst Daniel Geer, formerly the CTO of @Stake, was allegedly fired for co-authoring this report that purports that Microsoft's monopoly on operating systems and its tight integration of software constitutes a huge security risk to the world's technology infrastructure.

More details on the firing.

Discuss (Join / Login first) Edit   permalink: #  

A Conversation with Joshua Bloch on Java 2, SE 1.5
The new language features all have one thing in common: they take some common idiom and provide linguistic support for it. In other words, they shift the responsibility for writing the boilerplate code from the programmer to the compiler.

An interesting release. From my C++ experience, the new generics feature is like the late Charles Bronson, an ugly as sin syntax but quite an attractive feature once you get used to the initial looks.

And here is feedback from some real Java programmers (read the comments for a plethora of views). Also see the Stephen Jungels article on 1.5.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

PHP Component Model (PCOM)
The goal of this project is to develop a standard for the development of exchangable components that can be customized and plugged together using PHP Development Environments (PHP IDEs). -- Sebastian Bergmann

Very interesting. To make this succeed, we need to get through the hard part, which is agreeing on what common set of services everyone will support. To illustrate, here are some issues that come immediately to mind:

What exception mechanism will be supported if an invalid event or service occurs? I like PHP5's try/catch, but I dislike PEAR's error handling because it interferes with my in-house error handling mechanism.

Who is responsible for serialization and storage of component settings/properties? What serialization protocol will be used? For phpLens, we decided that we had no choice but store the properties as PHP code for speed.

Are multiple versions of the same component allowed like in .NET? PHP does not have an OOP model that allows multiple classes with the same name to co-exist.

There needs to be some dichotomy between edit and runtime modes. Different sets of services will need to be available. How will this work?

PS: I emailed Sebastian asking him to setup a Wiki/mailing-list on this. Lets see what happens.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

Harry Fuecks and the Control Freaks
Harry explains his thoughts on processing logic for web pages. I like Harry's conclusion, but looking at the twisted way the conclusion was derived, all I can say is: Harry, I think your mind has been warped by too many design patterns. Throw them away and breathe freedom :-)

I also like this:

Put bluntly, what I'm saying here is I think most of the PHP frameworks out there today have got it "wrong". And yes this site is guilty of exactly these "crimes"...

In my opinion, there is too much mindless imitation of .NET and Java out there. Remember that PHP is a dynamic language, and many of the design choices in .NET and Java do not make sense for PHP.

Here's an example of something that is very hard to implement in VB.NET or C# or Java: PHP can dynamically recompile itself; the famous Smarty template compiler being just the tip of the iceberg. There is a world of PHP innovation out there beyond cloning PHPNuke or J2EE, just waiting to be discovered!

PS: Something different: Leendert Brouwer has posted an essay on template engines.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

J2EE, .NET and PHP at MIT
A project done in Java will cost 5 times as much, take twice as long, and be harder to maintain than a project done in a scripting language such as PHP or Perl. People who are serious about getting the job done on time and under budget will use tools such as Visual Basic. -- Phil Greenspun

The nice thing about Java is that it is a good general purpose language. Unfortunately that strength also means that it is really good at nothing, and is a handicap in domain specific areas. You can argue that C# has the same defects as Java, so why is C# is easier to use? The evidence shown here hints why Java has failed in this area.

PS: The responses posted in comments are interesting also.

Discuss (Join / Login first) Edit   permalink: #  

Code bloat and benchmarking database libraries, round 2
Recently, I came across this thread at SitePoint about code bloat. This is an issue because PHP in its default configuration has to recompile all scripts on execution. So comments and complex logic have to be reparsed on each request.

Now Shakespeare would have said, "Much ado about nothing." In Malaysia we say: "All talk, no action-lah!" If you really are interested in speed simply install a PHP accelerator which compiles your PHP once, and subsequent requests will use the cached compiled script. Then this is a non-issue.

Some of you might say you are in a shared hosting environment and your ISP doesn't provide an accelerator. Well, the fact that you're using shared hosting probably means the ability to operate under a heavy load is not really a requirement. And I have heard of shared hosting companies kicking out users with badly designed databases and badly designed SQL, but never for parsing overhead. Gentlemen, you are missing the forest for the trees.

Here's a benchmark I recently did that demonstrates this:

This is a round-trip benchmark using a HTTP benchmarking tool, 
M'soft Web App Stress Tool (WAST). We measured with Turck MMCache 
Accelerator 2.3.23 installed and without. 

The tests were run as a variation of the above tests, e.g.

<?php include_once('../benchdb/_adodb.inc.php');

$db =& Connect(); QueryOnce($db,1); ?>

Two runs were taken and averaged for each test. Higher values are better. All measurements in pages/second.

With No Accelerator Accelerator MySQL 83.53 81.35 ADOdb 61.19 21.33 PEAR DB 52.85 25.26

This shows for best performance for any PHP software, you should use an accelerator that pre-compiles your PHP code. The reason why ADOdb benefits so much from an accelerator is that ADOdb is a bigger library than PEAR DB.

I must also add that the reason why ADOdb can be big but fast is that the code is designed like an onion, with a very small and fast core, and additional functionality layered on top as functions that call the core. If you don't need the extra functionality, use the core functions. And if you do need more power, it's already there.

PS: I enjoy reading you guys who post at SitePoint. I might not agree with everything you say, but it's great stuff.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

InterAkt PHP Enterprise Survey results are out
The PHP Enterprise Survey was created to help all parties involved in the PHP Market understand it better, and thus create better businesses based on it. We hope we've gathered sufficient information to become a reference for anyone wanting to show that PHP is a viable alternative for Intranet/Extranet applications and website development. -- InterAkt

My first reaction was to look at this slide. When you are in business, you are always interested in what other people are charging. I can safely say from the results that my company is not a typical PHP company.

Discuss (Join / Login first) Edit   permalink: #  

.Net? Java? No Thanks, We'll Take Macromedia Instead
Because of Flash's flexibility in designing interfaces, Mitem was able to duplicate the forms doctors fill out in examining patients. "Physicians are very busy, productive people who often don't have time to learn new technologies," Kelly said. "So the more we can make technology fit current methodologies, the more likely it will be successful." -- Antone Gonsalves

Membership in the I-hate-Eolas club must be growing. Thanks to Andrew for the link.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Will a New Software Strategy Lift the Dark Clouds Over Sun?
When I spoke to Schwartz he was speaking in superlatives. "This is the demise of the middleware industry," was his first bit of likely hyperbole. It went on from there. "We plan to take a $20 billion market and turn it into a $3 billion market," said Schwartz. "But in so doing I think we will gain a significant amount of share against those who are trying to sell hand-tooled middleware." You’ve got to hand it to this guy—he’s glib. -- David Kirkpatrick

A brave strategy for risky times. The way I see it, if Sun is successful, a price war will ensue with software vendors such as BEA and IBM. And with such lean profits on software and Intel hardware encroaching, Sun will have to buy up some software and system integrator companies to complement Sun's product lines and sustain revenues.

tri: Economist's viewpoint.

tri: Sun Product Line: Java Enterprise System. PHP will continue to be one of the supported languages for their Web server.

tri: Wes Felter points out that "their Mad Hatter Linux distribution is officially called Java Desktop System, even though there's not much Java in it. It seems particularly risky to recommend that ISVs write GNOME desktop applications in Java when Sun hasn't demonstrated that that's even feasible."

Discuss (1 response) (Join / Login first) Edit   permalink: #  

James Coplien: Putting the Object back into OOD
The two greatest books on OOP ever written (IMHO) are Bertrand Meyer's "Object-Oriented Software Construction" and James Coplien's "Advanced C++ Programming Styles and Idioms". Bertrand Meyer is a writer of great power and clarity. Very witty in person too.

In contrast, Jim's intellectual style throws you into the deep-end, and struggling to keep up is half the fun. Reflecting on what he says is a good way of developing a deeper understanding of OOP. Unfortunately this style of writing turns some people off. To see what I mean, you can read Jim's new blog:

Hierarchy has become an important abstraction tool in many design paradigms. Used effectively, it brings organizational power. Used to shed essential complexity, it is evil. In most object oriented design, most abstraction is evil. It is an excuse to ignore things we don't want to deal with even though we should.

Discuss (Join / Login first) Edit   permalink: #  

MetaL goes mental
Harry Fuecks poses a question and gets a ton of responses.

Every once in a while run into a project that leaves me wondering. Was vaguely aware that Manuel Lemos (phpclasses) was doing something with Metabase, an alternative to PEAR:B now somehow part of PEAR as well.

Via phpkitchen ran into this: http://www.meta-language.net/

Wondering if anyone has an experience of what Manuel's done here?

Also read Martin Fowler's opinion of MDA, which is another system similar to MetaL in concept, but backed by some big fish.

It's true that selling MDA for platform independance is hogwash, but developing high level models of an application is useful. High level conceptual models built using CASE tools can work provided:

  1. The model is not the code. It provides a framework and a methodology to organize your code under, and you don't have to do everything in the CASE tool.

  2. The model has a good or existing mapping for the problem domain. I would be suspicious of a CASE tool that claims it is suitable for any sort of programming.

  3. The model provides added value for the domain, such as user authentication, security, forms management, application variables for a web application.

  4. Sensible code is generated - many horrible UML tools generate hundreds of source code files for even simple apps.

  5. The system has 2-way synchronization of information, where key changes in the code that affect the model are picked up by the CASE tool.

  6. Graceful code generation, that does not overwrite existing code. Delphi and Visual Studio.NET are my models here.

Discuss (Join / Login first) Edit   permalink: #  

Versioning, Virtual, and Overrides, a Conversation with Anders Hejlsberg
We will never catch up. We will never fill all the capacity that Moore's law is heaping on us. The way we get more functionality these days is by doing more and more leveraging of existing infrastructure and existing applications. As systems are becoming longer lived, versioning is becoming more important. -- Anders was the lead designer of TurboPascal, Delphi, and C#.

Discuss (Join / Login first) Edit   permalink: #  

Sting like a BIFF, float like a PDF
Gentlemen, today is the day we settle our differences in the pugilistic ring. This will be a fight to remember, where we finally settle which format is the best in the world for report-writing. In this corner, we have the bull, Mr. BIFF, that fine format supported by every spreadsheet known to man. And in this corner, we have the perve from PCP4, proudly strutting in the knowledge that it is PDF and read-only.

Let the fight begin. Round ONE!

The fight begins, and Mr BIFF, who outweighs PCP4 by $7000, and powered by the strength of Excel, Quattro Pro, Lotus 1-2-3 and VisiCalc, throws a gigantic punch immediately. PCP4 spins around, nimble like a bee and evades BIFF. BIFF to his horror realizes what PCP4's read-only PDF attribute means. What cannot be modified cannot be hurt. With a thousand little punches, the boy from 'dobe stalks Mr BIFF. Mr BIFF is steak.

When interviewed later, PCP4 thanked his dad, Alex Wirtz, and said he couldn't have won the fight without the killer instinct he developed when studying for the Apache license. Another cheap victory for open source.

PS: Thx to Christian Pelczarski for the pointer to PCP4.

Discuss (2 responses) (Join / Login first) Edit   permalink: #  

Big Teams, Big Iron, Big Action: the Making of Oracle 10g
Kumar explains how the development grid increased productivity: "If I change my code, I might have to run it through 250 hours of testing before I can check it into the source control system," he says. "In the old days, I'd have to tie up my workstation. Now, I just send the test request to the development grid, which takes that 250 hours of testing and breaks it down into 100-plus streams. If 100 machines are available in the server farm, the tests will run simultaneously on those 100 machines. So, instead of waiting for 250 hours, I could potentially get the test results back in a couple of hours."

Awesome, but I'm glad I don't work at Oracle. This sounds too much like hard work.

Discuss (Join / Login first) Edit   permalink: #  

Lightbulb and Lumenation
This interesting software was reviewed in the September 2003 issue of PHP Architect which I received a few days ago. Its an application builder with report writer, and it looks quite user-friendly just from looking at their flash demos. Does not appear to be open source.

Things are still in a state of flux on their web-site though, with broken flash and images links. The review mentions a very strange decision by the developers. They currently only support Mozilla, which cuts them off from 99% of the market.

Update: Don Keeler responds to PHP Architect: [This] is a misconception. All applications created with Lumenation can be used within IE 5.5+.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

The Myth of External Program Documentation
In many ways, a good design document is like a novel. It speaks of a world thus far only fictitious, in a tense that makes it sound like it already exists. "The program does this and this and that..." Since most engineers are poor writers (or, at least inexperienced novelists), it is no wonder good design documents are hard to find.

I think it goes beyond that, however. It takes some courage to put things in writing and then live with the consequences. Going on the record may not be in your (personal) best interest -- even if you're right. And, of course, being wrong, in writing, can hang about your neck like the proverbial albatross. -- B. Scott Andersen

Quite frankly, I think that Scott is either playing devil's advocate, or he has a very narrow view of software development (a nice way of saying dumbass). I admit I work without writing much documentation initially, but at the end of the coding, a prodigious amount of documentation is produced - any examination of my work with adodb or phplens demonstrates this.

And we are all influenced by open source practices. A lot of projects for clients are delivered with source code nowadays. Customers will demand external documentation. Saying that we shouldn't bother because programmers are incapable of writing good documentation is simply irresponsible and insulting to many of us.

PS: Another read of the essay reveals that Scott is an XP advocate. Aha! You are the sum of your prejudices :-)

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

If you dig back into your Windows 95 files, you'll find that some internal system functions are given names like BEAR35, BUNNY73 and PIGLET12. Surely there is a story behind these silly names, isn't there?

Of course there is. -- Raymond Chen

Discuss (Join / Login first) Edit   permalink: #  

ADOdb 3.90: The Performance Monitoring Beta Out

The ADOdb performance monitoring library provides both CLI and HTML interfaces for viewing key performance indicators of your database. This is very useful because web apps such as the popular phpMyAdmin currently do not provide effective database health monitoring tools. You can view the online docs here, and download it here.

The library provides the following:

  • A quick health check of your database server using $perf->HTML() or $perf->CLI().
  • Continious polling of database and web server for key performance indicators such as CPU, Hit Ratio, Disk I/O with $perf->Poll($pollsecs).
  • Presents a central location for viewing selected critical database settings.
  • Generates a list of suspicious SQL statements that are good candidates for optimization for Oracle (and hopefully other databases in the future).
  • Gives you an API to build database monitoring tools for a server farm, for example calling $perf->DBParameter('data cache hit ratio') returns this very important statistic in a database independant manner.
  • Many databases are supported. In the beta, we have MySQL, PostgreSQL, Oracle (oci8), DB2, and MSSQL.


 $conn = ADONewConnection('mysql');
 $perf =& NewPerfMonitor($conn);
 echo $perf->HTML(); # generate HTML table

## FOR Oracle, we also support (requires 8.1 or later): echo $perf->SuspiciousSQL(); echo $perf->ExpensiveSQL(); ?>

Sample output (for HTML version) - note the health check warnings in red:


Parameter Value Description
MyISAM cache hit ratio 56.5658301822 Cache ratio should be at least 90%
InnoDB cache hit ratio 0 Cache ratio should be at least 90%
sql cache hit ratio 0  
data reads 2622 Number of selects (Key_reads is not accurate)
data writes 2415.5 Number of inserts/updates/deletes * coef (Key_writes is not accurate)
Data Cache  
MyISAM data cache size 512K  
BDB data cache size 8388600  
InnoDB data cache size 8M  
Memory Pools  
read buffer size 131072 (per session)
sort buffer size 65528 Size of sort buffer (per session)
table cache 4 Number of tables to keep open
current connections 3  
max connections 100  

You can also Poll the database continiously using $perf->Poll($pollsecs) to get CPU, hit cache and io statistics. Here is an example with $pollsecs=3:

Accumulating statistics...
 Time   WS-CPU%   Hit%           Reads/s          Writes/s
11:08:30    0.7  56.56            0.0000            0.0000
11:08:33    1.8  56.56            0.0000            0.0000
11:08:36   11.1  56.55            2.5000            1.0000

This beta release provides a structure for building more advanced database and server monitoring tools in the future. I hope this serves as an impetus for other developers to build more effective tools based on this package.

Discuss (Join / Login first) Edit   permalink: #  

Status of the PHP Compiler
Marco has been busy with his neat project:

This leaves me to the next part, which is the really tricky one: translating certain features of PHP in C code. For some of them, the trade off between their availability and the complexity and overhead they introduce in the final compiled code simply makes their introduction counterproductive. A typical example of this is variable variables (e.g.: $$a). In the scripting language, their existence does not cause any significant overhead, since variables are maintained in a lookup table and that mechanism has to exist anyway in order for the interpreter to function properly. Once compiled to C, however, variable names lose all meaning, and getting rid of lookup tables is one big speed improvement, since all variable access is done by means of a direct memory lookup.

Therefore, in some cases it's necessary to compromise and simply remove some features. I've always thought that variable variables are a pretty bad idea anyway... so I'm not really that worried about them.

Marco is thinking of generating standalone C executables with the PHP compiler. This means creating your own C runtime for PHP, and dropping some features that are too hard to implement. I think it's fantastic that Marco is sharing with us his struggles, but I have a different perspective.

To me, the most natural purpose of a PHP-C compiler is not to create stand-alone programs, but to convert PHP classes or functions into PHP Extensions. Then all the tough parts of building a PHP compiler, such as the large PHP function library and good stuff like eval() and function_exists() will work because you are stilll using zvals and you still have the PHP-runtime available.

AFAIK, no one is taking this approach. Well I think there would a ready market for such a technology in PHP web-sites that need to speed up their existing code. I would certainly pay good money for such a compiler. Any takers?

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

Commercializing Open Source Software
Looking at the software development process, integration issues, and numerous business models for open source software and commercial hybridization, one observation becomes clear: There is no such thing as free software.

Sure, you're free to download the software and you're free to modify it, but it's important to remember that both volunteers and employees have contributed their time to make available no-cost software for other users. Some projects, including the original BSD releases, were funded by grants from government or industry to develop software that was made widely available.

In addition, integration of free software components involves a cost that must be considered. Many organizations and individuals fail to recognize the significant time and cost integration work can take. And, of course, initial cost and integration are not the end of the story: Updates, patches, version upgrades, and technical support are an ongoing overhead. -- Michael J. Karels

Discuss (Join / Login first) Edit   permalink: #  

PHP growing surprisingly strongly on Windows
Omnia Vincit PHP - explained.

Discuss (Join / Login first) Edit   permalink: #  

Whatsup for ADOdb 4.0
Well I received the MNCC OSS Award today. Shook hands with our Minister of Energy, Communications and Multimedia and several nice bigwigs, got a nice certificate, and a plaque that I had to return immediately (getting it corrected, I got the wrong citation). Thanks again to all the people to contributed to this award, including you developers, MNCC and the sponsors, Maxis and the Malaysian Government.

As part of the celebration, here's a sneak preview of some docs I am writing for ADOdb 4. Ignore the version number, it will change.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

Sense and Sensibility with MVC
Model-View-Controller (MVC) is a software pattern that is often used for controlling web page access. Selkirk talks in the above link about the problems of using MVC with PHP.

PHP does not have the same run time environment. Each request initializes a fresh PHP environment. A front controller implementation in PHP has to take this into account because it is going to incur the costs of initializing its data structures on every request. It also incurs an overhead of dispatch.

I mistrust the requirement that every action in your web application has to have an entry in a central file. This seems to me like it would inhibit your ability to move code between web applications and make it difficult to move things around in your file stucture and in your URL structure.

Selkirk uses an alternative way of designing his apps, and it is exactly the way we do it over here. I have the same opinion as Selkirk, except that I have been unable to express myself so eloquently. Apparently this alternative style has a name too, Page Controllers.

The above link on MVC highlights the fact that many design decisions made by Java web apps presume the existence of a persistent Java Virtual Machine (JVM) that lingers around between HTTP requests. This also means you can store persistent state information in the JVM. PHP doesn't work that way. Everything is reloaded on every page request. It might not be wise for a PHP design to mimic Java patterns that require the loading of a large amounts of global configuration information or in-memory caching. Another pattern I would view with suspicion for similar reasons would be Data Access Objects.

Does this reloading of all data on every HTTP request mean that PHP is not scalable? Fortunately, as I've said before in other posts, that's a superficial view of things. The reloading of data is precisely the reason why PHP is scalable. The way PHP works encourages you to code using state-less designs. State information is not stored in the PHP virtual machine, but in separate mechanisms, a session variable handler or a database.

This makes PHP very suitable for highly scalable shared-nothing architectures. Each webserver in a farm can be made independent of each other, communicating with a central data and session store, typically a relational database. So you can have 10 or 1000 identically configured PHP web servers, and it will scale linearly, the only bottleneck being the database or other shared resources, not PHP.

Of course, things are not so simplistic. It is still possible to implement MVC efficiently with PHP. You define your action mappings in a high-level format, then compile the mappings with a code generator, so the MVC mappings become very efficient PHP code. The MVC libraries that I am familiar with do not do this, but it is not difficult.

One of the nice things about PHP is that it is a very good language for two-way code generation. When you generate code, PHP does not need to be compiled. And when you are parsing PHP code to regenerate meta-information, it's very easy to recognize variables because they always begin with $. Functions such as method_exists(), function_exists() and eval() are your friend, as they can also be used to identify code changes.

One example of code generation that might give you ideas is the applet design of phpLens, in which we have two way code generation. Change an applet value in the source code, and phpLens will autodetect it when it does an eval() of the code. Change an applet value from the web interface, and it is reflected in the generated source code.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

PostgreSQL, Inc. Releases Open Source Replication Version
PostgreSQL, Inc. is today contributing its commercially developed replication solution, eRServer(c) v1.0+ for the PostgreSQL database, to the PostgreSQL project and the global open source community. This is part of PostgreSQL Inc.'s ongoing commitment to promoting open source software by adding a crucial enterprise component to the world's most advanced open source database.

Replication is one of the most critical utilities for enterprise databases, and this release makes that capability accessible to qualified developers and users who could not previously afford replication because of software licensing or support fees.


Discuss (Join / Login first) Edit   permalink: #  

A richness of tutorials on ADOdb
A good week for ADOdb documentation.

PHPFreaks has recently published a very nice tutorial on ADOdb in which he explains the ADOdb equivalents of all the mysql_* functions.

For the longest time, I was stubborn to try new things, especially when it altered the way I develop PHP. After constant pressuring from a few fellow developers (thanks Daeken, ASleep and Rhapsodi) about using a database querying library, I decided to give ADOdb a shot. I must say, I am very impressed.

Then I got a message from Light Tseng that he has translated the ADOdb tutorial I wrote into Chinese.

Lastly I have rewritten the ADOdb connection documentation thanks to the urging of some friends to document all known connection issues.

Discuss (Join / Login first) Edit   permalink: #  

Oracle to support PHP in next release of Oracle App Server
Perl, another popular scripting language, is currently provided via mod_perl when Perl capability is desired on OHS. While Oracle does not support the Perl interpreter and language, it does support versions of OHS which include mod_perl, will assist in configuration and inclusion of mod_perl into OHS and is included on Oracle Application Server CDs. Also, Oracle will assist in diagnosing some Perl problems and will forward bugs to the relevant open source development organizations. Oracle plans to support PHP in the same way as it now does Perl. In addition, Oracle is considering additions of a number of value adds when using PHP with Oracle infrastructure.

Good news for PHP developers using Oracle (that includes me!) I have developers in my company who have developed applications for MySQL, PostgreSQL, Oracle, RDB, MS SQL Server, MS Access and Visual FoxPro. By universal consensus, Oracle is the best database we have ever used. Why?

  • Oracle is so complex and difficult that you are guaranteed never to be without a job once you learn it.
  • An Oracle DBA earns more than a MySQL lackey.
  • Memorable nights due to the most awful install process i have ever seen, next to Linux version 0.01.
  • The best justification for buying bigger hard disks ever - a fresh install of Oracle alone takes a couple of Gig's. And they recommend 4+ hard disks for an optimal installation.
  • Sexy 3rd party tools you should kiss like TOAD.
  • Unbelievable scalability. Unfortunately you only have 10 users, so i guess you over-paid.
  • Your management loves you, because you always recommend Oracle, the bleeding edge of technology, bleeding money that is.
  • Your management hates you, because you always recommend Oracle, even though cheaper alternatives exist.
  • You hate your management, so you always recommend the most expensive database, Oracle.

Jokes aside, we have a core set of PHP components that we develop using Oracle as our primary database. We like Oracle, and developing with it is really productive when you are using TOAD, PHPLens and ADOdb. Then on every release of our components, we port to other databases.

Thx to PHP Developer and PHP Kitchen for the OAS info. Also for more info on Oracle, visit these two resources.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

PHP 4.3.3 released
After a lengthy QA process, PHP 4.3.3 is finally out! This maintenance release solves a fair number of bugs found in prior PHP versions and addresses several security issues. All users are *strongly* advised to upgrade to 4.3.3 as soon as possible.

Download: http://www.php.net/downloads.php

PHP 4.3.3 contains, among others, following important fixes, additions and improvements:

  • Improved the engine to use POSIX/socket IO where feasible.
  • Fixed several potentially hazardous integer and buffer overflows.
  • Fixed corruption of multibyte character including 0x5c as second byte in multipart/form-data.
  • Fixed each() to be binary safe for keys.
  • Major improvements to the NSAPI SAPI.
  • Improvements to the IMAP extension.
  • Improvements to the InterBase extension.
  • Added DBA handler 'inifile' to support ini files.
  • Added long options into CLI & CGI (e.g. --version).
  • Added a new parameter to preg_match*() that can be used to specify the starting offset in the subject string to match from.
  • Upgraded the bundled Expat library to version 1.95.6
  • Upgraded the bundled PCRE library to version 4.3
  • Upgraded the bundled GD library to version GD 2.0.15

  • Over 100 various bug fixes!

For a full list of changes in PHP 4.3.3, see the ChangeLog.

Discuss (Join / Login first) Edit   permalink: #  

Notorious applications for PHP
PHPQuébec is about to publish the first PHP DVD ever. The PHP Québec Conference, in Montreal, is leading this project. It will gather 7 hours of high level PHP sessions.

Coming with the two DVD case, a CDrom will be included, with the most notorious PHP application, made for or with PHP. PHP Québec is looking for your help to gather the most common applications, and add them in this CDRom.

Take advantage of your time on the web site to learn more about this exciting DVD case, made specially for those who couldn't join us in Montreal, last March. Current prices are still early bird tariffs, much cheaper.

links :
PHP Québec CDrom

PHP Québec DVD case

Discuss (Join / Login first) Edit   permalink: #  

PHP-Con West Early Bird Announcement
Subject: Online Registration opens for php-con West 2003, October 21-24, 2003, Santa Clara, California

php-con returns to the San Francisco Bay Area with new sessions, the gurus of PHP and a whole new day of PHP-intensive learning. Log on to http://www.php-con.com/ today for program details and online registration.

php-con West 2003: Community. Code. Solutions.
October 21- 24, 2003
Biltmore Hotel
Santa Clara, California

Why is php-con the destination of choice for PHP and web developers? Because php-con is about three things: Community. Code. Solutions.

Community. PHP developers all share a common goal: Getting the most out of the Web. And php-con is the where the PHP developer community comes together to advance that goal.

Code. php-con program packs in full-day tutorials, three tracks of technical sessions and the all-day developer marathon: The php-con Code Sprint. Write, debug and test your code along side PHP's finest.

Solutions. php-con is where you will find everything you need related to robust, rapid applications development, standards and best practices: MySQL, PostgreSQL, XML, PEAR, Webservices, PHP-Gtk, PHP/GD, testing and debugging, performance tuning, and extending PHP.

Don't wait to secure your space at php-con! Early Bird Registration discounts end on September 26, 2003. Register online today at http://www.php-con.com/. Information on student discounts are available on our registration page.

Discuss (Join / Login first) Edit   permalink: #  

ADOdb wins Malaysian Open Source Software Award
I just got word that ADOdb has won the Malaysian National Computer Confederation OSS Award 2002/2003. As the recipient, thanks to all of you developers who contributed to the success of the project.

Its not been officially announced yet, but i got a phone call from a representative of MNCC. The Minister of Energy, Communication and Multimedia, Datuk Leo Moggie, will be presenting the awards at a ceremony next week.

PS: This appears to be a good time to update my bio.

Discuss (6 responses) (Join / Login first) Edit   permalink: #  

Speeding up Zend Engine 1: Faster, Stronger, Harder
O wonder!
How many goodly creatures are there here!
How beauteous mankind is! O brave new world
That has such people in’t!

Sterling and Thies rewrite large parts of the core engine of PHP, resulting in amazing speedups.

What does it do?

Now i am not an expert on PHP internals, and there are probably several optimizations that i missed, but one obvious one i think i can understand is this. PHP is parsed and compiled into low-level opcodes. The following code taken from zend_execute.c (before the improvements) is the interpreter that executes the opcodes, and is a giant switch statement in a while-loop.

	while (1) {
 		switch(EX(opline)->opcode) {
-			case ZEND_ADD:
-				EG(binary_op) = add_function;
-				goto binary_op_addr;
-			case ZEND_SUB:
-				EG(binary_op) = sub_function;
-				goto binary_op_addr;
-			case ZEND_MUL:
-				EG(binary_op) = mul_function;
-				goto binary_op_addr;
-			case ZEND_DIV:
-				EG(binary_op) = div_function;
-				goto binary_op_addr;

In the new code, we see:

+			L(ZEND_SUB):	do_binary(sub_function);
+			L(ZEND_ADD):	do_binary(add_function);
+			L(ZEND_MUL):	do_binary(mul_function);
+			L(ZEND_DIV):	do_binary(div_function);

L(ZEND_*): is a C-preprocessor macro that generates a goto-label. The do_binary() is not a function, but a devilish macro (see the definitions of do_binary and NEXT_OPCODE) that generate gotos to jump to the next opcode label. In plain language, we now cache the address of the next opcode to execute, instead of choosing the next opcode to run in a switch statement. And the while-loop is optimized away, as we jump directly to the next opcode handler after the current opcode is executed.

This sort of algorithm is very popular when you code in assembler, and is proof that C is actually a macro assembler - you couldn't do this in Java. I have a vague recollection that some Lisp and Forth intepreters were implemented like this. Perhaps someone can eludicate on this.

PHP 4.4 anyone?

New: A detailed writeup on the optimizations has been posted by Sterling.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

Five Habits for Successful Regular Expressions
A nice article that shows how little i know about regular expressions. I particularly liked the part on lazy quantifiers and inserting comments in your regular expressions. Very useful.

PS: Back from my day trip to Singapore. Had to wake up at 4.30am to catch the flight, which is closer to my bed-time than my wakeup time.

Discuss (Join / Login first) Edit   permalink: #  

A fractal view of PHP
Creating fractals with PHP is a great way of learning mathematical programming. However you might remember the way of the Dragon is to avoid PHP altogether. If you bring your ears close to a fractal as it is being drawn, you can hear it squeek, "when i grow up, i want to become an extension."

tri: Highly recommended for Macs/Windows: Aros Fractals.

PS: I will be away in Singapore tomorrow.

Discuss (Join / Login first) Edit   permalink: #  

.NET's 18,000-Mile Checkup
Eighteen months after Microsoft Corp. delivered .NET, early adopters are weighing in with real-world reports of what it’s like to work with the application development framework. -- Jennifer deJong

Discuss (Join / Login first) Edit   permalink: #  

Flame Warriors
Hilarous. Every viewpoint from Godzilla to God.

Discuss (Join / Login first) Edit   permalink: #  

Laughing Meme teaches developing software libraries for PHP
Great advice, a recapitulation of all the mistakes to avoid in developing libraries by Kellan, based on his experiences developing MagpieRSS.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

MS Windows (and HTML_toPDF) made me a masochist
I just tried this PHP class for converting HTML to PDF. I also discovered something about myself: I am a masochist - because only someone crazy would try to install it on Windows. The amount of additional software I had to install and configure was postively painful: perl, html2ps, imagemagick and ghostscript.

All that work gave me a good insight into how the script runs, because the page sizing was wrong, and i had to patch the PHP script and the ghostscript batch files to make it work.

You have to generate your HTML first and store it in a file. Then from the HTML_toPDF script, you run the perl script html2ps to convert it to postscript. The imagemagick software is needed if you want to convert any images to postscript. Then ghostscript is run to convert the postscript to pdf format.

The end-result was a reasonable approximation of the HTML for some test pages, but i had very large pages that generated invalid postscript, and for other pages the HTML table proportions were badly off. The 72dpi graphics rendered are really crude and hurt my eyes. If you want to feel my pain, here is one sample HTML page I tested, and the resultant PDF. In the PDF, the bottom toolbar is drawn in the middle of the grid on page 3. The page numbers are wrong too.

This is a great hack, but use it only if you have very basic HTML files (no complex tables), or have the time to tweak the HTML and debug html2ps. This pain-puppet says: a bit too painful for me after all.

tri: PDF unfit for human consumption

Discuss (12 responses) (Join / Login first) Edit   permalink: #  

Smoke and Thunder: Flames about PHP in the Enterprise
I stumbled on this thread recently, and I like this post by brainpipe best. It's exactly how I feel, and how we use PHP at our company:

So if enterprise-ready means you can make it work for enterprise systems, then yes, PHP is there. If it means ready to work for enterprise systems out-of-the-box, then no, PHP has a very long way to go. But I really don't see the point in arguing about it. Why not throw all that mental muscle around making PHP more powerful?

Once you know a language inside-out, and can call yourself (honestly) an expert, it starts to lose its luster for you. It's easy to get caught up in a language that's relatively new to you and think it's the ultimate solution. But there is no ultimate solution. PHP is a wonderful language imho, and I absolutely love it. Even so, if I were designing the system I've helped build at work, I would have chosen Java and either Postgres or Oracle for the lower-level work, and PHP for the front-end.

Unfortunately, through sheer momentum, the dialogue didn't end there - if you are curious, you can wade through all 150+ posts.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Bridging the gap between .NET and J2EE
The ease of use of Visual Studio.NET, Microsoft's tools platform for .NET, is the winning factor, along with close ties into Windows that make it easy to squeeze every last drop of functionality out of the environment. A senior executive at one of the big SIs, nervous to go on the record for fear of upsetting either camp, estimates a 30 percent productivity advantage with .NET.


J2EE's biggest trump card over .NET is its ability to deploy to a heterogeneous server environment, whereas .NET is limited to just Windows servers. "In a big company, you are not deploying on Windows, you are deploying on Windows, HP-UX, Sun Solaris and a variety of platforms," says one Java developer. This means, says Sholay, that BEA rarely competes with .NET products because the two operate at different levels of the enterprise, J2EE being at the mission-critical end.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

SitePoint: Exploring the Limits of CSS
For better or worse, the vogue of Web design has evolved to favour a layout similar in style to a newspaper. Common design elements include:

  • a header and footer that each spans the page horizontally content constrained by page width
  • vertical scrolling is acceptable, within reason
  • navigation and secondary content in vertical columns next to the main content

That last one is the real kicker. The sad reality is that the current CSS specificaton (CSS2) was not designed with multiple columns of content in mind. As a result, just as Web designers have always had to abuse HTML tables to achieve complex page layout, they must now abuse CSS positioning to achieve those same ends. -- Kevin Yank

I have noticed a marked improvement in the quality of articles at SitePoint. Keep up the good work, Kevin.

tri: Also see Look Ma, No Tables at glish.com, and the improved 3-col layout in the following SitePoint article.

Discuss (Join / Login first) Edit   permalink: #  

The Way of the Dragon: Parsing XML with PHP
Listening to the radio as i type this. The speakers are blaring the 70's hit, Kung Fu Fighting right now. Yeah. "Those kids were fast as lightning!"

The way to speed in PHP is a bit like Tai Chi, working indirectly, avoiding PHP code and using the strength of the hidden, the inner C of PHP, functions hand-crafted for speeed.

In this forum posting, Selkirk demonstrates his mastery of the Way, with a 1500% speedup in parsing XML by avoiding PHP, controlling the power of his C[hi] with a flick of strpos(), blessed with the purest economy of memory allocation.

btn: Thx to PHP Patterns for the pointer.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Tim Bray: Flash versus DHTML user interfaces
The usability problem wasn’t anything wrong with Flash intrinsically, it’s just that we couldn’t get it to feel enough like being in a browser. It was really, really hard to get the Back button working properly, and even things like letting people type in a query and launch it by pressing Enter (as apposed to clicking on a button) were a challenge.

Maybe we’re not world-class Flash wizards, but we tried pretty hard and just couldn’t get that smooth clean browser integration. People are just not willing to tolerate the Back button’s not working properly in a browser-based application.

The performance problem was more surprising, because in theory we should have won. You generate XML on your server, you parse it on the client, you generate vector graphics on the client, you’re using less bandwidth and you’re splitting the CPU load between your server and the immensely-fast boxes on most modern desktops. This is what I’d call nice clean architecture. -- Tim Bray

Nearly a year ago, I was evaluating Flash as an alternative to DHTML. I ended rejecting Flash for similar reasons. I suspect that a lot of readers know that modern web browsers will dynamically render HTML and execute your javascript even before the DHTML files are fully downloaded. But we take it for granted, without realizing how much a difference this dynamic rendering makes to the user experience.

In contrast, Flash files have to be fully downloaded before anything interesting occurs. Even with Flash remoting, where the Flash code is downloaded once then HTTP is used as a communications protocol for retrieving only data, Flash was noticably slower. Flash just doesn't have the benefit of over 10 years of R&D on displaying HTML quickly.

tri: A good example of poor use of Flash. No resizing, no back button, slow Flash remoting (note how long it takes to render a message with lots of replies). My previous post on this topic.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

plPHP for PostgreSQL
Another milestone for PHP. A major Open Source project has implemented PHP as an embedded language for their software - and it wasn't MySQL! Thx to Joshua Drake for doing this.

Discuss (4 responses) (Join / Login first) Edit   permalink: #  

InterAkt's Enterprise PHP Survey is online
Take part in the survey and share your feedback!

Discuss (1 response) (Join / Login first) Edit   permalink: #  

PHP market research
Alexandru COSTIN, Chief Operating Officer of InterAkt, asked me to post this interesting series of questions:

I've searched the net for various information on PHP usage in the enterprise. I've searched Forrester, Gartner and Google with little results.

I know some popularity report exists here (http://php.weblogs.com/popularity) and I also know that Zend has made this survey but they are both missing some essential figures on money, enterprise acceptance and so on.

We would also think creating a survey of our own - but we know that only a company like Zend would be able to attract many other respondents from more various areas than we do.

I would appreciate any figures on the web development market - because this is the market for most of us - and knowing the market could only be a good thing. I think we should consider this key figures:

1. How many PHP websites are developed per year in your company

1.1 What kind of applications bring the best profit (CMS/Intranet/ERP/CRM/Dynamic Website)

2. Turn-over per year from PHP websites/company.

3. Turn-over per year from PHP websites/employee.

4. Where is your company heading in terms of market strategy - offer low cost solutions, offer professional web development solutions, etc.

5. ASP/Java competition estimates (how many sites/application do they do, how much is the market share for them?)

6. Some real market information for total web development/country would also help to determine the PHP market share for all those information.

7. Are PHP programmers spending money on software development tools or pre-built libraries?

8. Why do companies "reject" PHP solutions and how what should we do to improve their feelings on this?

We are also open on any suggestions on this research's goal - as probably there are others that know better how to do a market research.

Would this kind of survey work? Are there any political problems that could prevent people filling it? We have a survey software and we would be glad to create a public survey with those information that could help all PHP developers convince their clients/bosses/partners that PHP is a viable enterprise choice. I hope that you are also willing to change the conception on PHP as the "Personal/low end" scripting language.

I'm looking forward to your comments. -- Alexandru

tri: The survey is now online here: http://iakt.rdsnet.ro/interakt/survey/?survey_id=12

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

Don't Monkey with my Code...
I'm offended that these guys don't program in PHP. Don't they know that PHP is for ...

PS: Cathleen is one sexy chick.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Leendert Brouwer rants about PHP and patterns
Leendert argues that using Design Patterns are useful with 3GL's such as C++ and Java, but are an overkill in many cases with PHP.

tri: Martin Fowler: Patterns are nothing new

Discuss (Join / Login first) Edit   permalink: #  

ADOdb for PHP5
I want to get some feedback how ADOdb (the database wrapper library i maintain) can take advantage of the PHP5's new functionality. Here are some of ideas:

SPL Iterator Support

PHP5 will come with the SPL extension built-in. This extension gives us a very elegant way of iterating through recordsets. We can extend the behaviour of foreach, allowing us to do this:

$rs = $conn->Execute('select * from table');
foreach($rs as $key => $row) {
The initial $key value for the recordset will be 0.

Exception Handling

ADOdb will support the new exception handling of PHP5, where ADOdb will throw an exception when an error occurs. You will also have option of the old PHP4 method of returning the error as a result. This will probably be determined by setting a global variable ($ADODB_EXCEPTIONS = true).

For those of you who care about these things, when iterating through a recordset, arriving at EOF will not cause an error - it is a natural part of processing a recordset. The exact format of the exception class (ADOdbError extends exception) is open for debate.

Feedback is very welcome at the ADOdb forums.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

PHP Magazine: Running Multiple Threads in PHP
In PHP Magazine, there is one column I always turn to, "Ask A PHP Guru". Readers submit interesting questions to a panel of PHP experts.

Today I just received the April issue (english edition), and a reader had this interesting question:

Is there a way to do a form of threading in PHP? Say for instance you write a PHP application to monitor a service on a number of servers, it would be nice to be able to query a number of servers at the same time, rather than query them one-by-one.

In their answer, one of the gurus (probably Wez) suggests using non-blocking sockets in PHP4, or the new non-blocking streams feature in PHP5, to asynchronously query the servers. The article also provides sample source code for PHP4 and PHP5.

This is a pretty neat solution if you want to do parallel processing or asynchronous polling with PHP. Of course these solutions don't really use threads, so they lack the one property that makes threads so useful: the sharing of global data. Still not a big deal if you are using this technique to manage a large server farm.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

PHP5 is sexy: Coming Soon to a Webserver Near You
They say the best sex is when its flavored with love and anticipation. You get the feeling that Harry Fuecks feels the same way about PHP5. A pity his website is down.

Discuss (Join / Login first) Edit   permalink: #  

Spaghetti, Private Members and Bloat
Sterling Hughes responds to my some of my posts:

This is not about spaghetti coding as Peter Moulding (or John) might suggest. This is actually about separating your error handling logic from your coding logic, leading to more readable code.

The point that Peter and I made is that try/catch is the mythical man-month of reliability. Try/catch is just a different way of checking for errors, and will not improve code robustness without additional planning.

You are correct about unified error handling leading to more readable code, Sterling, but that is only in a perfect world. For try/catch to work really well, you need to have a unified exception model, where the only way any error is generated is by throwing an exception. But PHP5 will have a messy mixed error model due to legacy code which returns errors and does not throw exceptions. This can lead to mistakes in error-handling as one function requires checking a return value, but the other function throws an exception. Bruce Eckel points out this flaw in C++ too.

Peter Moulding prefers to remain conservative and consistent, avoiding try/catch and mixed metaphors. Others might prefer a massive refactoring exercise on their existing code to use try/catch consistently. I do use try/catch, but we need to be more aware of the trade-offs, and clearly separate what types of errors are thrown, what types of errors still use the old check the return value method, and what constitutes an error (if strpos returns false, is it an error?)

Private members. This is about maintaining an interface contract with your users. Private is not, as many people seem to think, a way of restricting access to member variables. That is the end affect, but rather its about programmatically enforcing an interface contract.

_private in Python is a gentleman's contract. You can build very large class libraries with this convention. The proof is in the Python.

Its funny you don't even mention abstract classes which are, and have always been useless bloat.

Surprisingly, I quite like interface, abstract and protected. They are the building blocks for standardized extensible components, something I have always felt was lacking in PHP. Of course, i haven't looked at how this was implemented internally. Are you implying that these features will be nearly as slow as the release process of PHP5?

I suspect that in the end, we will all use the subset of PHP5 we like. Rasmus will continue to prefer procedural, the PEAR folks OOP, and I will use one or the other depending on my mood and the phase of the moon.

Discuss (3 responses) (Join / Login first) Edit   permalink: #  

Free Culture
A great story in Flash format about copyright, control and culture by Laurence Lessig. After seeing it, you really wonder whether it is possible that living in less advanced countries like Malaysia and Russia gives you more freedom. Not because they are more benevolent, not because they are run better, but because these countries are less organized and more chaotic, so you have more opportunities and they have less control over you.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Processing Incoming Email with PHP and an MTA
They say that ignorance is bliss, but that's a lie. Ignorance is a waste of time, forcing some poor fool (me in this case) to do a lot of dirty, low-level, and totally unnecessary work.

This fantastic technique that i just learnt from Gijs van Tulder allows you to intercept emails as they come into an email server. This is very useful if you are developing email workflow, routing emails intelligently based on its contents. My previous solution for this was really really hard work, requiring a custom C++ dll that interfaced to a commercial email server's API.

Discuss (1 response) (Join / Login first) Edit   permalink: #  

Get your site hosted using Manila!
Free Software
A high quality database library:
ADOdb 4.22   download
New Netezza, LDAP and odbtp_unicode drivers.
ADOdb for Python
ADOdb Help & Dev Forum

ADOdb Documentation:
  - English
  - Francais
  - Korean
  - English
  - Chinese
  - German
  - Italian
  - Polish
  - Russian
  - Spanish
  - Thai

3rd Party Tutorials:
  - MelonFire Part 1
  - MelonFire Part 2
  - PHPFreaks
  - Database Journal Part 1
  - Database Journal Part 2


ADOdb Articles:
  - PHP4 Sessions with ADOdb
  - Cool ADOdb applications
  - ADOdb testimonials
  - Comparing PEAR DB and ADOdb
  - Writing Portable SQL
  - Web Services with ADOdb
  - ADOdb date library

-Commercial data component: phpLens

Our RSS Newsfeed
PHP Advocacy
Michael Kimsal
Zeev Suraski

-Comparing PHP with .NET
-PHP versus ASP
-Why PHP is better than ASP
-PHP versus Cold Fusion
-PHP versus Perl
-What's wrong with JSP?
-PHP,ASP,JSP,CFM Popularity
-PHP Humor

Enterprise PHP
-Enterprise PHP scalable, high availability
-Writing Reliable Software
-PHP Application Variables
-Sessions in a Server Farm with ADOdb
-PHP, FastCGI and IIS

-Optimizing PHP: tips, methodologies and examples.
-Tuning PHP and Apache: many tips and links.

PHP Articles
-PEAR Tutorials & Links
-PHP Windows/Unix Editors
-PHP Caches & Debuggers

-XML-RPC Web Services
-ActiveX on Linux
-GD on Windows
-Using mail()

Some notes comparing PHP, JScript, VBScript and ASP that might be useful
1. Language Basics
2. Functions, Classes
3. ASP Objects and PHP

-My Favorite Articles
-CVS on Windows

PHP and SQL Databases
-SQL Tutorials & Resources
-Transactions in MySQL
-Flying with MySQL & Oracle
-Object-Relational Mania
-MySQL vs MSSQL vs Access
- also see ADODB above.

Apache and IIS
-Unix Performance Analysis
-Securing Apache on Linux
-Porting Apache to IIS
-Windows Apache & PHP

-Var_Dump & Print_R
-Prevent Caching
-E-mail Your Errors
-Disable magic_quotes_gpc
-Stop Submitting Twice
-Document Code Quickly
-Fault Tolerant Connections
-HTTP Compression
-XML DOM for Windows

PHP.Net Home Manual Bugs
Writing a PHP Extension
Zend.com: PHP Portal
PHPBuilder.com: Articles
HotScripts Code Snippets
PHP Resource Index
PHP Source Code ChangeLog

Evil Walrus
phpinfo.net: French e
phpitalia.com: Italian e
phparchiv.de: German
php-resource: German e
PHP-Center.de: German e
phpuser.com: Chinese
hot PHP Web Cards
Cool Javascripts
More Links

Learn PHP
Forums Ask for HELP here!
or try the KnowledgeBase

Good Intro to PHP
PHP Overview by Rasmus
Intro to PHP

Regular Expressions Intro   txt2regex
Advanced Reg. Expressions
Database Readings PalsLib

Bad Blue: Web Server
phpBB: Excellent Forum
ASP2PHP: Converts VB to PHP.
Web Calendar Nice

-My Favorite Articles

PHP4.0.4 Installer
php_gd.dll with GIF

Put the following ADODB logo on your website if you like!

John Lim Malaysia Natsoft Juris Legalpro iJuris mydevotion Tips Juris LensServer Ormes Technologies.

All original materials (c) 2000-2004 John Lim