I’m in the process of optimizing a site and am just getting my feet wet with caching. In particular, I’m using Zend_Cache to cache some database results and am hoping to expand what I cache. I have one file, which is approximately 1000 lines long and consists of all of the function definitions for my site. Of course, only a few functions are called in any given script, but for organizational purposes, I thought that this was the way to go. With this in mind I have a couple of questions.
Is there a way to “cache” my function definitions script?
How can I measure what I actually save if I cache something? (in other words, I know that I can measure how long a script takes to run, but what are the other resource expenses?)
Thank you for answering these questions. There will probably be more of a similar flavor in the next few days.
You could…but it would be pointless…Replace one I/O request for another is not going to save anything. What you truly need is a opcache. An opcache is where PHP parses the PHP source files into byte code and saves those for latter, so it doesn’t need to constantly parse your source files. In most cases opcache also saves to memory instead of a hard drive.
And, might you have a suggestion where I can begin to understand benchmarking processes? I feel a little bit like a guy who can drive a car pretty straight without going off the road, but I have no clue how the car works under the hood…
If you want to delve into what is happening on your dev machine, then start off with installing the xdebug extension.
Then move on to generating and analysing cachegrind files - that starts getting you closer to the metal.
Watch out though, such navel gazing is akin to hanging out your car window watching your tyres go round in order to see if you are wasting fuel, when in fact you could be asking “why am I even going on this journey?”
re APC : further to logic_earth’s reply, APC (when I last used it) came with a utility enabling you to see (and control) which parts of your script are cached, enabling you to see how often they are accessed etc – this can be very insightful