Coding "init" functiosn for an extension...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lee Stewart

    Coding "init" functiosn for an extension...

    Another question about writing PHP 5 extensions. What's the difference in
    PHP_MINIT() / PHP_MSHUTDOWN() and PHP_RINIT() / PHP_RSHUTDOWN() ? When would
    a "per request" init be made?


    Thanks,
    Lee
    LeeStewart @ gmail.com


  • Mike Willbanks

    #2
    Re: Coding "init&quot ; functiosn for an extension...

    Lee,

    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_st art 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..



    Mike[color=blue]
    > Another question about writing PHP 5 extensions. What's the difference in
    > PHP_MINIT() / PHP_MSHUTDOWN() and PHP_RINIT() / PHP_RSHUTDOWN() ? When would
    > a "per request" init be made?
    >
    >
    > Thanks,
    > Lee
    > LeeStewart @ gmail.com
    >
    >[/color]

    Comment

    • Lee Stewart

      #3
      Re: Coding "init&quot ; functiosn for an extension...

      > All of this is explained in the zend extension tutorials..[color=blue]
      > http://www.zend.com/php/internals/ex...n-writing1.php
      > http://www.zend.com/php/internals/ex...n-writing2.php[/color]

      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.


      Thanks!
      Lee
      LeeStewart @ gmail.com


      Comment

      Working...