SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast kaklz's Avatar
    Join Date
    Mar 2004
    Location
    Latvia, Riga
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Problematic code for eAccelerator, Zend optimizer, APC, mmcache, xcache, etc.

    I've been searching the internet for best practices on writing php code that can be cached well using the ocpode cache mechanisms, however all I can find is just tutorials on how to install, how to configure and the performance benchmarks regarding various opcode cache packages.

    What I'm looking for is some kind of guide what code can be cached and what can't.

    For example yesterday I watched the PHP Architect's webcast about PHP opcode cache:
    http://www.phparch.com/webcasts/reco...rding.php?ID=7

    The problem is that the presentation includes very few examples of problematic code.

    In our project we use eAccelerator and the eA stats say that about 1000 files are cached. The problem is that the whole source tree includes about 4000 files (eA still states it has enough free memory). It means that only 25% of the files are cached.

    Maybe somebody can help me out with some comments.

    As far as php Architect's presentation states, code like

    PHP Code:
    <?php 

    if (condition) exit;
    class 
    Foo{}

    ?>
    is problematic, just because PHP compiler does not know whether it needs to define the class or not, as there is no information in compile-time about the value of the condition.

    The same applies to
    PHP Code:
    <?php 

    if (!class_exists('foo')){
    class 
    Foo{}
    }

    ?>
    This is easily solved by just using require_once or include_once. As far as I understood the php opcode caches have problems with conditional includes of OO source. The question is whether the same problems apply if we don't use OOP approach and instead of class definition there is simple html output?

    I mean if we just have structure like:

    PHP Code:
    index.php
    <?php 
    if (condition){
    include (
    'some_code_block.php');
    }
    ?>
    PHP Code:
    some_code_block.php:
    <?php 
    echo 'hello world';
    ?>
    Is this code problematic for opcode cache packages as well?

    And one more question - is there any performance gain in opcode caching by using procedural programming approach versus OOP approach?

    Too bad I missed the live event of presentation, otherwise I would have asked it directly to the presentation author.

    Thanks in advance!

  2. #2
    SitePoint Zealot cholmon's Avatar
    Join Date
    Mar 2004
    Location
    SC
    Posts
    197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's a thread from pecl-dev mailing list about APC and how it works (or doesn't) with conditional code, especially autoload.

    Regarding procedural versus OO, I wouldn't think there'd be much of a difference between the two, cached or not. I personally prefer the OO approach for the sake of my code's overall organization and readability, even if that means sacrificing a few microseconds of execution time that I might otherwise save with a procedural system.
    Drew C King: PHP Developer
    <?= $short_tags++ ?>

  3. #3
    SitePoint Enthusiast kaklz's Avatar
    Join Date
    Mar 2004
    Location
    Latvia, Riga
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, thanks for the link, I guess the main problem is the conditional class definition loading..


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •