As the first comment mentions; requests are only served in response to clients; none of the language constructs of PHP should be described as requests.
As simple as I can make it ...
Execution is a three stage process:
- Load file from disk
- Compile into Zend's intermediate form
- Execute intermediate form
A cache improves performance by usurping those parts of Zend normally responsible for loading files from disk and compiling it to Zend's intermediate representation; such that, if possible, the loading and compilation stage of execution can be bypassed, improving performance.
Without an Opcode Cache
When a request is made such as
GET /index.php HTTP/1.1
The web server servicing the request is invoked in the normal way, which in turn invokes the PHP interpreter. The interpreter then loads index.php
from disk, compiles it into Zend's intermediate representation, and begins executing the code.
When a script contains a statement such as
include "my_awesome_code.php";
The (same) interpreter loads my_awesome_code.php
from disk, compiles it into Zend's intermediate representation and executes it.
With an Opcode Cache
When a request is made such as
GET /index.php HTTP/1.1
The web server servicing the request is invoked in the normal way, which in turn invokes the PHP interpreter. Rather than loading index.php
from the disk, the cache retrieves the code from memory where it is stored in something very close to the form of Zend's intermediate representation. Preparing the cached code (which means copying from shared memory and finalizing it's form) for execution is much faster than loading from disk and compiling to that representation first.
When a script contains a statement such as
include "my_awesome_code.php";
The codes are again retrieved from the cache, bypassing compilation once again.
Should the cache not be able to find index.php
or my_awesome_code.php
in shared memory, it invokes the parts of Zend it usurped; resulting in the normal loading from disk and compilation of those codes into Zend's intermediate representation. The cache intercepts the resulting intermediate code and stores it in shared memory before allowing it to be executed for the first time.