Includes and APC

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Includes and APC

Post by Ambush Commander »

Read this blog post, and then report back here.

I think I vaguely understand it. But I probably don't, since I haven't the foggiest idea of what I need to do to prevent this problem. Can anyone elucidate?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

It's easy - stick everything into one file ;). Your performance will beat anything else needing includes.

Gopal's analysis is pure illumination. For the last two years people have been asking these questions and not getting a simple convincing answer. You should see where the PEAR2 debate over dropping *_once constructs as a requirement has gone over the last few months.

I think this illustrates one point - APC is screwing up a little. Yes, it works, but it's only going to work best when you put all your PHP classes into one giant file to be cached (Greg Beaver's benchmarking earlier today showed an incredible oddity running APC with stat=0 emphasising this). Otherwise, classes which inherit from as yet unmet parents, won't be as efficiently cached (parent not yet hit, so it requires additional opcode for later execution when the parent is finally available).

APC needs fixing - hopefully prior to being released in PHP6 publicly. Until then it's PEAR2 style out-the-window thinking (even if it unintuitively makes good sense right now).
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Interestingly enough, that's exactly what I've done. Go me! :-) (actually, it's a preprocessor the rolls up all the PHP files into one big one; works essentially the same way)

APC has it tough, since unlike Java where the one class per file convention is strictly enforced, PHP has no such rules. Which makes things complicated.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I thought there was discussion on the Zend Framework list about this and that they were going to address the include_once() problems in upcoming PHP5 releases? I have not used the _once() functions in a while because they have had problems since their conception. When they were first added they had separate file lists -- what a mess.
(#10850)
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

PHP5.2 included some optimisations for the *_once functions (I think it was a realpath cache?) but the main problem above is with APC. So while PHP5.2 is faster for using *_once, APC still won't cache everything as efficiently as it could.

Not that the Zend Framework has ever seen XDebug anyway ;). I've never seen much of a concerted optimisation effort post 1.0.
Post Reply