Page 1 of 1
Why can't PHP introduce something like Beans in Java?
Posted: Sun Jan 08, 2006 8:30 am
by raghavan20
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...
Posted: Sun Jan 08, 2006 8:55 am
by Roja
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.
The PHP answer is a PHP Accelerator, like
http://www.php-accelerator.co.uk/
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.
Posted: Sun Jan 08, 2006 1:27 pm
by Jenk
a PHP (non-runtime) compiler?

Posted: Sun Jan 08, 2006 1:36 pm
by Weirdan
Jenk wrote:a PHP (non-runtime) compiler?

there are quite a lot of those... check bcompiler, for example
Posted: Sun Jan 08, 2006 4:07 pm
by Jenk
bcompiler != native compiler.
It's the raw performance increase that compilation provides I'm after, not fussed about encrypting my source.
Posted: Sun Jan 08, 2006 4:18 pm
by feyd
I know you can embed the core of php into an exe pretty easily..
Posted: Sun Jan 08, 2006 7:07 pm
by Weirdan
Jenk wrote:bcompiler != native compiler.
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.
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
Posted: Mon Jan 09, 2006 2:52 am
by Jenk
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.
Posted: Mon Jan 09, 2006 7:02 am
by timvw
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...
Posted: Mon Jan 09, 2006 7:10 am
by m3mn0n
Roja wrote: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.
The PHP answer is a PHP Accelerator, like
http://www.php-accelerator.co.uk/
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.
Good news to hear. It'd be very useful indeed.
Posted: Mon Jan 09, 2006 8:34 am
by raghavan20
timvw wrote:
With php you can also compile source to zend virtual machine. And afterwards this code is executed by the zend virtual machine...
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?
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?
Posted: Mon Jan 09, 2006 8:55 am
by timvw
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...
Posted: Mon Jan 09, 2006 9:27 am
by Maugrim_The_Reaper
Rasmus wrote a phpArchitect article for APC back maybe 2 months ago... In case anyone with access has forgotten. As if...