Coding "init" functiosn for an extension...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Another question about writing PHP 5 extensions.  What's the difference in  
a "per request" init be made?

LeeStewart @  

Re: Coding "init" functiosn for an extension...


When you have all of those, there are ones that they call when the  
extension is initialized and when shutdown.  That is the simple explanation.

Now for the more explained description:

PHP_MINIT - Module Initialization.
This gives each extension a chance to initialize internal variables,  
allocate resources, register resource handlers, and register its  
functions with ZE, so that if a script calls one of those functions, ZE  
knows which code to execute.

PHP_RINIT - Request Initialization.
RINIT gives the extension a chance to set up specific environment  
variables, allocate request specific resources, or perform other tasks  
such as auditing. A prime example of the RINIT function in action is in  
the sessions extension where, if the session.auto_start option is  
enabled, RINIT will automatically trigger the userspace session_start()  
function and pre-populate the $_SESSION variable.

PHP_MSHUTDOWN - Module Shutdown.
During shutdown of php it calls all of the PHP_MSHUTDOWN functions and  
then shuts down its core subsystems.

PHP_RSHUTDOWN - Request Shutdown
This allows you to preform all the last minute cleanup on the extension  
and save anything that you might need to save.

Hope that helps...
All of this is explained in the zend extension tutorials..

Quoted text here. Click to load it

Re: Coding "init" functiosn for an extension...

Quoted text here. Click to load it

I was using existing extensions to get details on how to implement one of  
these - thanks for the pointer to the docs!  The "lifecycle" is especially  
useful for me, since I need to be careful when I initialize and free data.

LeeStewart @  

Site Timeline