svn: /phpdoc/en/trunk/reference/session/functions/ session-set-save-handler.xml

From: Date: Sun, 26 Feb 2012 05:36:07 +0000
Subject: svn: /phpdoc/en/trunk/reference/session/functions/ session-set-save-handler.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-9682@lists.php.net to get a copy of this message
drak Sun, 26 Feb 2012 05:36:07 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=323552 Log: [session-set-save-handler] Update information about closing down sessions handlers which are objects. Changed paths: U phpdoc/en/trunk/reference/session/functions/session-set-save-handler.xml Modified: phpdoc/en/trunk/reference/session/functions/session-set-save-handler.xml =================================================================== --- phpdoc/en/trunk/reference/session/functions/session-set-save-handler.xml 2012-02-26 05:30:34 UTC (rev 323551) +++ phpdoc/en/trunk/reference/session/functions/session-set-save-handler.xml 2012-02-26 05:36:07 UTC (rev 323552) @@ -184,6 +184,11 @@ example could easily be extended to cover database storage using your favorite PHP supported database engine. </para> + <para> + Note we use the OOP prototype with <function>session_set_save_handler</function> and + register the shutdown function using the function's parameter flag. This is generally + advised when registering objects as session save handlers. + </para> <programlisting role="php"> <![CDATA[ <?php @@ -247,7 +252,7 @@ </programlisting> </example> <example> - <title><function>session_set_save_handler</function> example</title> + <title>Custom session save handler using objects</title> <para> The following code is for PHP versions less than 5.4.0. </para> @@ -257,6 +262,12 @@ example could easily be extended to cover database storage using your favorite PHP supported database engine. </para> + <para> + Note we additionally register the shutdown function <function>session_write_close</function> + using <function>register_shutdown_function</function> under PHP less than 5.4.0. + This is generally advised when registering objects as session save handlers under PHP less + than 5.4.0. + </para> <programlisting role="php"> <![CDATA[ <?php @@ -338,14 +349,15 @@ <para> When using objects as session save handlers, it is important to register the shutdown function with PHP to avoid unexpected side-effects from the way - PHP internally destroys objects on shutdown. Typically you should register - <parameter>'session_write_close'</parameter> using the + PHP internally destroys objects on shutdown and may prevent the + <parameter>write</parameter> and <parameter>close</parameter> from being called. + Typically you should register <parameter>'session_write_close'</parameter> using the <function>register_shutdown_function</function> function. </para> <para> - As of PHP 5.4.0 you can use <function>register_shutdown_function</function> or + As of PHP 5.4.0 you can use <function>session_register_shutdown</function> or simply use the 'register shutdown' flag when invoking - <function>session_set_save_handler</function> using the OOP method (passing an + <function>session_set_save_handler</function> using the OOP method and passing an instance that implements <classname>SessionHandlerInterface</classname>. </para> </warning> @@ -354,11 +366,14 @@ As of PHP 5.0.5 the <parameter>write</parameter> and <parameter>close</parameter> handlers are called after object destruction and therefore cannot use objects or throw exceptions. + Exceptions are not able to be caught since will not be caught nor will + any exception trace be displayed and the execution will just cease unexpectedly. The object destructors can however use sessions. </para> <para> It is possible to call <function>session_write_close</function> from the - destructor to solve this chicken and egg problem. + destructor to solve this chicken and egg problem but the most reliable way is + to register the shutdown function as described above. </para> </warning> <warning> @@ -402,6 +417,8 @@ The <link linkend="ini.session.save-handler">session.save_handler</link> configuration directive </member> + <member>The <function>register_shutdown_function</function></member> + <member>The <function>session_register_shutdown</function> for PHP 5.4.0+</member> </simplelist> </para> </refsect1>

« previous php.doc.cvs (#9682) next »