Why can't PHP introduce something like Beans in Java?
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
Why can't PHP introduce something like Beans in Java?
I recently started programming in JSP and I find Beans to be extremely useful and I think the concept of compiling of Beans is very rewarding. I see tremendous speed in which JSP applications work. The bean classes are normally kept in a web-inf/classes folder and they are compiled to class files and the class files are used by JSP files. This is very good becaue in most of the situations, beans are not altered and there is no point interpreting them everytime.
In PHP, we write classes like Paginator, DBConnection, FileUploader and many others, most probably in a separate PHP file. But everytime when we include these class files in the PHP files, it gets intrepreted unnecessarily everytime but we rarely modify these classes. Instead I think, these kind of classes should be mandatorily aggregated in to a separate classes folder and compiled to some intermediate code. The next time, the PHP includes these classes, it should run intermediate code....this can make the codes work faster...
In PHP, we write classes like Paginator, DBConnection, FileUploader and many others, most probably in a separate PHP file. But everytime when we include these class files in the PHP files, it gets intrepreted unnecessarily everytime but we rarely modify these classes. Instead I think, these kind of classes should be mandatorily aggregated in to a separate classes folder and compiled to some intermediate code. The next time, the PHP includes these classes, it should run intermediate code....this can make the codes work faster...
The PHP answer is a PHP Accelerator, like http://www.php-accelerator.co.uk/raghavan20 wrote:But everytime when we include these class files in the PHP files, it gets intrepreted unnecessarily everytime but we rarely modify these classes.
And before you say "But Java does it by default, and PHP doesnt!", keep in mind that the current plan is for PHP6 to have one enabled by default.
It depends on your definition of 'native compiler'. Granted, bcompiler does not produce target processor's opcodes, it doesn't even seem possible due to the php being dynamic interpreted language.Jenk wrote:bcompiler != native compiler.
But in this sense javac.exe isn't native compiler as well.
It's the raw performance increase that compilation provides I'm after, not fussed about encrypting my source.
PHP Manual wrote: bcompiler can improve performance by about 30% when used with uncompressed bytecodes
bcompiler will still need to be "decompiled" to an extent so that the PHP/Zend engine can interpret it - and as I also pointed out, you need to install the bcompiler extension with the script in order for it to run - if PHP gains a native compiler, this will not be an issue as the compiler is included with the install. (Though it will be a few years after PHP6 release before this is the 'standard')
javac.exe is a native compiler - java.exe will not read code that has not been compiled, or atleast, not very well.
javac.exe is a native compiler - java.exe will not read code that has not been compiled, or atleast, not very well.
javac.exe will compile to java bytecode, instructions for a "java virtual machine". With java.exe you then start such a virtual machine, and all the calls on that machine are translated to the "native" instruction set of your computer.
With php you can also compile source to zend virtual machine. And afterwards this code is executed by the zend virtual machine...
With php you can also compile source to zend virtual machine. And afterwards this code is executed by the zend virtual machine...
Good news to hear. It'd be very useful indeed.Roja wrote:The PHP answer is a PHP Accelerator, like http://www.php-accelerator.co.uk/raghavan20 wrote:But everytime when we include these class files in the PHP files, it gets intrepreted unnecessarily everytime but we rarely modify these classes.
And before you say "But Java does it by default, and PHP doesnt!", keep in mind that the current plan is for PHP6 to have one enabled by default.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
are you talking about the feature in PHP that is going to introduced in PHP6 else you are talking about some special products from Zend which does that?timvw wrote: With php you can also compile source to zend virtual machine. And afterwards this code is executed by the zend virtual machine...
is native code the set of opcodes necessary for execution by a processor?
When you say something is interpreted...does it directly get converted to native codes, the set of opcodes?
Btw, the "free" variant of ionCube is apc.
The difference with java is that you start from source -> class (java bytecode)
and then you execute the bytecode in a virtual machine -> native instructions
With php the exact same process happends, but the regular interpreter doesn't 'dump' the bytecode.. It immediately passes it to the virtual machine.. With ioncube and apc you can 'dump' the bytecode... thus the next time you execute the code you don't have to translate it to bytecode first, but can immediately execute it in the virtual machine. I don't find good urls with better explanation right now...
The difference with java is that you start from source -> class (java bytecode)
and then you execute the bytecode in a virtual machine -> native instructions
With php the exact same process happends, but the regular interpreter doesn't 'dump' the bytecode.. It immediately passes it to the virtual machine.. With ioncube and apc you can 'dump' the bytecode... thus the next time you execute the code you don't have to translate it to bytecode first, but can immediately execute it in the virtual machine. I don't find good urls with better explanation right now...
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland