1>.sapi (mini version webserver), Minit (module initialization), Rinit (Extended request initialization method), Rshutdown (Request termination), Mshutdown (module termination)
First, life cycle: Initialize the Myextension module, call each extension's Minit (module initialization) After the SAPI is started, and then PHP then iterate through the extension, invoking the rinit of each extension (Extension request initialization method); After the request is processed, Call the Rshutdown (request termination) of each PHP extension to start the cleanup process; Finally, when the request is satisfied, webserver or SAPI is ready to terminate, invoking the Mshutdown (module termination) method of each extension, Extend the last time the processor is uninstalled and the opportunity to release persistent allocated memory
Two or four common SAPI (webserver): cli/cgi, multi-process templates, multithreaded templates, embedded
1>.CLI (and CGI) lifecycle processes:
$ php-f test.php ==> call each extension ' s Minit (Invoke module initialization method) ==> request test.php (Request test.php) ==> call each Exten Sion ' s Rinit (call extended initialization method) ==> Execute test.php (execute test.php) ==> call each extension ' s Rshutdown (Invoke extended Request termination method) ==> fi Nish cleaning up after test.php (cleanup play test.php) ==> calls each extension ' s Mshutdown (Invoke module termination method) ==> terminate PHP (terminating PHP)
2> multi-process life cycle (example: the form of a child process)
Minit Cycle
{rinit cycle,script execution,rshutdown cycle}php page Request
{rinit cycle,script execution,rshutdown cycle}php page Request
。。。。。。
Mshutdown Cycle
These sub-processes are independent of each other, and this pattern does not allow any child processes to know the data of other child processes, but it allows other child processes to be replaced without affecting the stable operation of other child processes
3> multi-threaded life cycle (open a process that contains multiple threads in execution, reduces some load, avoids repeated calls to Minit and Mshutdown, real global data is only assigned and initialized once)
Minit (Multiple threads inside a child process)
{Rinit,script,rshutdown},{rinit,script,rshutdown},{rinit,script,rshutdown},{rinit,script,rshutdown},{rinit, Script,rshutdown}
Mshutdown
4> embedded life cycle (a particular place may be infiltrated into multiple script fragments as part of an entire request, and in most cases control is passed back and forth multiple times between PHP and the calling application)
Module initialization-"Request initialization-" request-"Request Termination-" module termination
5>. Zend Thread Safety
TSRN (thread-safe resource management): Once a single process multithreading webserver appears, it is necessary to do a new approach to global data processing, and finally this as a new layer
Thread-safe Data pool: In the extended minit phase, the extension calls ts_allocate_id () once or more times to tell the TSRN layer that it needs to lock the data space, TSRN to be notified, will gross position the running space to the requested number of bytes, and return a new identity (when acquired, expand The current thread resource pool is requested from the TSRN layer, the ID returned by ts_allocate_id () as an offset)
In the case of a non-threaded environment, this TSRN layer requests the current thread resource pool to get an offset in a more efficient manner, so a struct is defined in the process's global space, that is, sample_g (sampleint) = 5; expanded is Sample_ Globals.sampleint = 5; Simple, fast and efficient
6>.
PHP extensions and Embedding (1)