# Patch for opcode caches

- Thread: https://externals.io/message/36168
- Original archive: https://news-web.php.net/php.internals/36168
- Started by Dmitry Stogov on 2008-03-17T12:23:54+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #36168 — Dmitry Stogov — 2008-03-17T12:23:54+00:00

URL: https://externals.io/message/36168#36168

> -----Original Message-----
> From: Marcus Boerger [mailto:mail@marcus-boerger.de] 
> Sent: Friday, March 14, 2008 9:28 PM
> To: Stas Malyshev
> Cc: internals@lists.php.net
> Subject: Re: [PHP-DEV] Patch for opcode caches
> 
> 
> Hello Stanislav,
> 
> Friday, March 14, 2008, 6:48:52 PM, you wrote:
> 
> > […]
> 
> > […]
> time. And no 
> > […]
> 
> > […]
> direction 
> > […]
> 
> Hmm, so other people must not read what we discuss, that does 
> not work.
> 
> > […]
> thing is not 
> > […]
> 
> That is my point. It can be done. 

Look into the example:

parent1.php
<?php
class Foo {...}
?>

parent2.php
<?php
class Foo {...}
?>

child.php
<?php
class Bar extens Foo {...}
?>

index1.php
<?php
include "parent1.php";
include "child.php";
?>

index2.php
<?php
include "parent2.php";
include "child.php";
?>

Do you still think if early-binding for class Bar is possible at
compile-time with opcode caches?
And what "Foo" is the parent?

> The reason to delay 
> inheritance is that we can have a conditional statement 
> around a class definition. 

There is no "if' statement in example above.
Also detection of conditional code is additional pine for caches.

> If we detect classes that do not 
> have conditionals around them, then we can bind them early.

It's wrong.
 
> It is as easy as that. So instead of making the language more 
> dynamic and even removing a chance of having inheritance 
> dones early where possible we should work on making the 
> desired case - eraly binding - as easy as possible.

The proposed patch allows caches to implement proper behavior of
early-biniding in most easy way. (~5 lines of code)

Thanks. Dmitry.

---

## #36184 — phpxcache — 2008-03-18T01:24:48+00:00

URL: https://externals.io/message/36168#36184 · In reply to: #36168

session (or caused by TSRM/ZendEngine) seems broken in my local cvs
checkout i'm not sure if it's relatived to this patch but i did 'cvs
up' and some commit broke the patch (with conflicts)
please commit, or roll out another diff against the PHP_5_3 cvs so i
can test it again

thanks

---

## #36188 — Dmitry Stogov — 2008-03-18T08:55:15+00:00

URL: https://externals.io/message/36168#36188 · In reply to: #36184

The patch has been just committed.
You should use something like the following code to make it work.

  function cache_compile_file($filename) {
           if (!is_cached($filename)) {
                   ...
                   orig_compiler_options = CG(compiler_optins);
                   CG(compiler_options) |= 
ZEND_COMPILE_IGNORE_INTERNAL_CLASSES |
                                           ZEND_COMPILE_DELAYED_BINDING;
                   $op_array = orig_compile_file($filename);
                   CG(compiler_options) = orig_copiler_options;
                   ...
           } else {
                   $op_array = restore_from_cache($filename);
           }
           zend_do_delayed_early_binding($op_array);
   }

Thanks. Dmitry.

phpxcache wrote:
> session (or caused by TSRM/ZendEngine) seems broken in my local cvs
> checkout i'm not sure if it's relatived to this patch but i did 'cvs
> up' and some commit broke the patch (with conflicts)
> please commit, or roll out another diff against the PHP_5_3 cvs so i
> can test it again
> 
> thanks
