-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathconnection-handling.xml
93 lines (87 loc) · 4 KB
/
connection-handling.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<chapter xml:id="features.connection-handling" xmlns="http://docbook.org/ns/docbook">
<title>Connection handling</title>
<para>
Internally in PHP a connection status is maintained. There are 4
possible states:
<itemizedlist>
<listitem><simpara>0 - NORMAL</simpara></listitem>
<listitem><simpara>1 - ABORTED</simpara></listitem>
<listitem><simpara>2 - TIMEOUT</simpara></listitem>
<listitem><simpara>3 - ABORTED and TIMEOUT</simpara></listitem>
</itemizedlist>
</para>
<simpara>
When a PHP script is running normally, the NORMAL state is active.
If the remote client disconnects, the ABORTED state flag is
turned on. A remote client disconnect is usually caused by
users hitting their STOP button. If the PHP-imposed time limit (see
<function>set_time_limit</function>) is hit, the TIMEOUT state flag
is turned on.</simpara>
<simpara>
You can decide whether or not you want a client disconnect to cause
your script to be aborted. Sometimes it is handy to always have your
scripts run to completion even if there is no remote browser receiving
the output. The default behaviour is however for your script to be
aborted when the remote client disconnects. This behaviour can be
set via the ignore_user_abort &php.ini; directive as well as through
the corresponding <literal>php_value ignore_user_abort</literal> Apache
&httpd.conf; directive or
with the <function>ignore_user_abort</function> function. If you do
not tell PHP to ignore a user abort and the user aborts, your script
will terminate. The one exception is if you have registered a shutdown
function using <function>register_shutdown_function</function>. With a
shutdown function, when the remote user hits his STOP button, the
next time your script tries to output something PHP will detect that
the connection has been aborted and the shutdown function is called.
This shutdown function will also get called at the end of your script
terminating normally, so to do something different in case of a client
disconnect you can use the <function>connection_aborted</function>
function. This function will return &true; if the connection was
aborted.</simpara>
<simpara>
Your script can also be terminated by the built-in script timer.
The default timeout is 30 seconds. It can be changed using
the <option>max_execution_time</option> &php.ini; directive or the corresponding
<literal>php_value max_execution_time</literal> Apache &httpd.conf;
directive as well as with
the <function>set_time_limit</function> function. When the timer
expires the script will be aborted and as with the above client
disconnect case, if a shutdown function has been registered it will
be called. Within this shutdown function you can check to see if
a timeout caused the shutdown function to be called by calling the
<function>connection_status</function> function. This function will
return 2 if a timeout caused the shutdown function to be called.
</simpara>
<simpara>
One thing to note is that both the ABORTED and the TIMEOUT states
can be active at the same time. This is possible if you tell
PHP to ignore user aborts. PHP will still note the fact that
a user may have broken the connection, but the script will keep
running. If it then hits the time limit it will be aborted and
your shutdown function, if any, will be called. At this point
you will find that <function>connection_status</function>
returns 3.
</simpara>
</chapter>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->