mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00
[session-set-save-handler] Update information about closing down sessions handlers which are objects.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@323552 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
a63190d9c4
commit
6afb06c369
1 changed files with 23 additions and 6 deletions
|
@ -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 @@ session_start();
|
|||
</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 @@ session_start();
|
|||
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 @@ session_start();
|
|||
<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 @@ session_start();
|
|||
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 @@ session_start();
|
|||
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>
|
||||
|
|
Loading…
Reference in a new issue