Zend optimiser can it compete with Java

They have: 426 posts

Joined: Feb 2005

So I have been looking to learn a new language namely Java.

It has more standards and everything is packaged better for security and management. But I originally thought that Java would be alot fast than PHP especially when processing data and making calculations: however, I came across Zend Optimiser server. So As I understand this will cache the interpreted / compiled PHP script for future use. So would this make PHP as fast as Java if the server is reading machine code rather than having to run it through the PHP engine before sending it to the browser?

PHP6 looks set to become really object orientated which is a good thing but can it compete with Java - just web based applications?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

In referencing using Java, are referring to just processing pages on the server side, or actually making stand alone apps or ones to run in the web browser?

For running in the browser, I normally run with Java support disabled, as I normally am running several browser windows at once, and I hate hitting a site that kicks up Java and I am forced to shut all occurrences of the browser to get it to shut back off.

They have: 426 posts

Joined: Feb 2005

HI Greg,

I am not refering to applets, but JSP and servlets running on Tomcat or J2EE and yes, I do mean internet based apps not stand alone apps - which actually is another reason for moving to Java so I can create Mobile apps and standalone apps.

But in terms of web based applications running on a web server, can zend optimiser compete with Java for performance and speed when processing data?

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Firstly, are you talking about Zend Optimiser or Zend Optimiser+? The former enables PHP to run files compiled by Zend Guard, the latter is an opcode cache and PHP optimizer. Great naming there, not confusing at all *rolleyes*.

Secondly, word on the street is that APC makes code faster than Zend Optimiser+ and even if it weren't it is going to be included in PHP 6 by default, so you should probably be using that instead. I haven't tested Zend vs. APC personally though, let us know if you find a site with benchmarks.

Thirdly, no, I don't think PHP+APC (or any other opcode cache) can match the performance of Java. There are two primary reasons for this:

  • PHP is dynamically typed whereas Java is statically typed. The PHP interpreter must check the types of variables at runtime, causing a performance hit.
  • Worse, PHP lacks a JIT compiler. This is a different animal to an opcode cache/code optimiser, JIT compilation makes bytecode into machine code before it is run, whereas an opcode cache only stores bytecode in shared memory, it only helps if you are include-ing a lot of files and would benefit from storing them in memory.

Hopefully this blog post will help make things clear: http://dow.ngra.de/2008/08/04/optimizing-ip2c-php-implementation/ I think the author gives PHP a bit of a bad rap, considering it really isn't made for heavy data processing duties but see his reply when someone complains at him for not using APC:

@Am Leben, @Jacek
I ran the tests with APC. The configurations I used were:

apc.enabled=1
apc.optimization=10
apc.enable_cli=1

No difference to the original results. Why? APC caches opcodes. So it eliminates the disk hit.

As I'm just running the script once and I'm actually just timing the loop that finds the country codes I'm not saving anything. About the apc.optimization the manual says "Expect very modest speed improvements. This is experimental." So my code does not get any faster.

Would I make large number of script executions it would make a difference but not in these circumstances.

So, as far as the speed of code execution goes, an opcode cache is pretty-much irrelevant.

Here's a better set of language benchmarks. If you have time, you should learn a variety of languages (Java, C/C++, C# etc.) so you can employ the one best suited to the task at hand.

a Padded Cell our articles site!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.