Hello all,
I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts in
the Zend Engines opcodes and execute directly when called.
The extension may have two functions.
bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.
gpc_import function accepting path to the compiled file and execute file
into the zend engine. I want to know perception of you all about this.
Thank you.
Deepak Balani
Hello all,
I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts in
the Zend Engines opcodes and execute directly when called.The extension may have two functions.
bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.gpc_import function accepting path to the compiled file and execute file
into the zend engine. I want to know perception of you all about this.Thank you.
Deepak Balani
Hi
Do you mean something like apc_compile_file()?
I think we already have it.
Or perhaps you mean runkit?
No I mean persistent compilation system like
Java
HelloWorld.Java -> HelloWorld.class
HelloWorld.php -> HelloWorld.gpc
When you call
gpc_import('HelloWorld.php');
then function first look for HelloWorld.gpc if found
then include it and if not then look for HelloWorld.php or HelloWorld.inc
(whatever the setting is) if found compile it and include it else raise an
error.
On Wed, Feb 22, 2012 at 11:25 AM, Flavius Aspra flavius.as@gmail.comwrote:
Hello all,
I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts
in
the Zend Engines opcodes and execute directly when called.The extension may have two functions.
bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.gpc_import function accepting path to the compiled file and execute file
into the zend engine. I want to know perception of you all about this.Thank you.
Deepak BalaniHi
Do you mean something like apc_compile_file()?
I think we already have it.
Or perhaps you mean runkit?
-----Original Message-----
From: Deepak Balani [mailto:wgpdeepak1989@gmail.com]
Sent: Wednesday, February 22, 2012 1:07 AM
To: flavius@php.net
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] PHP Script Compile SystemNo I mean persistent compilation system like
Java
HelloWorld.Java -> HelloWorld.class
HelloWorld.php -> HelloWorld.gpc
When you call
gpc_import('HelloWorld.php');
then function first look for HelloWorld.gpc if found then include it and if not then look for
HelloWorld.php or HelloWorld.inc (whatever the setting is) if found compile it and include it else
raise an error.
Can you explain how this is better or functionally different from the behavior of APC? APC caches bytecode this way too. Unless I've horribly misunderstood something, when you include the file APC uses the cached bytecode as long as it is available and the file was not since modified. If the file was modified APC recompiles it and caches the bytecode. Sounds like the same net result to me, except that APC is less complicated, requires no code changes, and automatically clears its own cache.
Did I miss something?
John Crenshaw
Priacta, Inc.
-----Original Message-----
From: Deepak Balani [mailto:wgpdeepak1989@gmail.com]
Sent: Wednesday, February 22, 2012 1:07 AM
To: flavius@php.net
Cc: internals@lists.php.net
Subject: Re: [PHP-DEV] PHP Script Compile SystemNo I mean persistent compilation system like
Java
HelloWorld.Java -> HelloWorld.class
HelloWorld.php -> HelloWorld.gpc
When you call
gpc_import('HelloWorld.php');
then function first look for HelloWorld.gpc if found then include it and if not then look for
HelloWorld.php or HelloWorld.inc (whatever the setting is) if found compile it and include it else
raise an error.Can you explain how this is better or functionally different from the behavior of APC? APC caches bytecode this way too. Unless I've horribly misunderstood something, when you include the file APC uses the cached bytecode as long as it is available and the file was not since modified. If the file was modified APC recompiles it and caches the bytecode. Sounds like the same net result to me, except that APC is less complicated, requires no code changes, and automatically clears its own cache.
Did I miss something?
There is also apc_bin_dump() and apc_bin_load() if you absolutely must
have something stored on disk, but assuming you are interested in the
performance aspect here, you don't want to be loading anything from disk
on a per-request basis. If the interest is along the lines of being able
to distribute obfuscated binaries or something, then this is completely
the wrong approach because it is trivial to reverse engineer unless you
add an encryption layer on top of it.
I think one thing that people miss when comparing the php compile phase
to java/c/c++ compilation is that compiling a php script to opcodes is
super fast because we don't do complicated optimization passes or any of
those things, so the performance you gain by only skipping the
compilation phase isn't actually that much unless you combine it with
also caching the op_arrays, function and class tables in memory.
Imagine needing to compile a C++ program on every request? That just
isn't feasible. Without an opcode cache, the PHP compiler runs on every
request and it is fast enough for millions of sites out there.
-Rasmus
complicated optimization passes or any of those things
Would such things be welcome/needed in the engine or as an extension?
complicated optimization passes or any of those things
Would such things be welcome/needed in the engine or as an extension?
Note that he said "complicated" :-)
There are many trivial / easy optimizations of low-hanging fruit.
It's just the out-of-band not-in-real-time complicated ones that PHP
doesn't do, shouldn't do, and won't do.
So if you find a quick easy one, it's most welcome...
The complicated ones, not so much :-)
PS
The misinformation that opcode caches "save" compilation time
routinely rears it's ugly head. Opcode caches save disk reads. Using
the already-opcoded chunk is just gravy, because the cache does this
(grossly over-simplified):
if ($opcode = opcode_cache_get($filename)){ //added by opcode cache
//do no disk I/O EXPENSIVE
//Oh, and for gravy, don't compile it.
}
else{
$source = file_get_contents($filename); //EXPENSIVE
$opcode = php_compile($source);
}
php_execute($opcode);
instead of this:
if ($source = opcode_cache_get($filename)){ //added by opcode cache
//do no disk I/O EXPENSIVE
}
else{
$source = file_get_contents($filename); //EXPENSIVE
}
$opcode = php_compile($source); //cheap and easy small optimization
missed
php_execute($opcode);
--
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE
Hi!
I am think(actually drafting) about the compilation system of PHP scripts.
I want to make a native C extension which is able to compile the scripts in
the Zend Engines opcodes and execute directly when called.The extension may have two functions.
bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.
Just FYI: such products already exist. Besides APC that was mentioned,
there's Zend Guard (commercial), ioncube encoder (commercial), bcompiler
and maybe more.
Out of curiosity - why you want to do this?
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227
I am think(actually drafting) about the compilation system of PHP
scripts.
I want to make a native C extension which is able to compile the
scripts in
the Zend Engines opcodes and execute directly when called.The extension may have two functions.
bool gpc_compile($source, $target): compile file to opcodes.
mixed gpc_import($target) Include file to current script.gpc_import function accepting path to the compiled file and execute
file
into the zend engine. I want to know perception of you all about this.
It sounds intriguing to me, if it can work reliably...
But what advantage is this over an opcode cache, really?
Now, if you could compile it to binary with make
that would be
REALLY interesting :-)
--
brain cancer update:
http://richardlynch.blogspot.com/search/label/brain%20tumor
Donate:
https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=FS9NLTNEEKWBE