Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 1892

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Connection handling</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="features.remote-files.html">Using remote files</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="features.persistent-connections.html">Persistent Database Connections</a></div>
 <div class="up"><a href="features.html">Features</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="features.connection-handling" class="chapter">
  <h1>Connection handling</h1>


  <p class="para">
   Internally in PHP a connection status is maintained.  There are 3
   possible states:
   <ul class="itemizedlist">
    <li class="listitem"><span class="simpara">0 - NORMAL</span></li>
    <li class="listitem"><span class="simpara">1 - ABORTED</span></li>
    <li class="listitem"><span class="simpara">2 - TIMEOUT</span></li>
   </ul>
  </p>

  <p class="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 the
   user hitting his STOP button.  If the PHP-imposed time limit (see
    <span class="function"><a href="function.set-time-limit.html" class="function">set_time_limit()</a></span>) is hit, the TIMEOUT state flag
   is turned on.</p>

  <p class="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 <var class="filename">php.ini</var> directive as well as through
   the corresponding <em>php_value ignore_user_abort</em> Apache 
   <var class="filename">httpd.conf</var> directive or
   with the  <span class="function"><a href="function.ignore-user-abort.html" class="function">ignore_user_abort()</a></span> 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  <span class="function"><a href="function.register-shutdown-function.html" class="function">register_shutdown_function()</a></span>.  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  <span class="function"><a href="function.connection-aborted.html" class="function">connection_aborted()</a></span>
   function.  This function will return <strong><code>TRUE</code></strong> if the connection was
   aborted.</p>

  <p class="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 <strong class="option unknown">max_execution_time</strong>
 <var class="filename">php.ini</var> directive or the corresponding
   <em>php_value max_execution_time</em> Apache <var class="filename">httpd.conf</var>
   directive as well as with
   the  <span class="function"><a href="function.set-time-limit.html" class="function">set_time_limit()</a></span> 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
    <span class="function"><a href="function.connection-status.html" class="function">connection_status()</a></span> function.  This function will
   return 2 if a timeout caused the shutdown function to be called.
  </p>

  <p class="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  <span class="function"><a href="function.connection-status.html" class="function">connection_status()</a></span>
   returns 3.
  </p>
 </div>
<hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="features.remote-files.html">Using remote files</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="features.persistent-connections.html">Persistent Database Connections</a></div>
 <div class="up"><a href="features.html">Features</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>