aktuelle.kurse/oldies/m133/4_Modulinhalte_und_Uebungen/00-Anwendungen-Beispiele-Uebungen/PHP_Referenz/funktionsreferenz/sonstige_funktionen/connection_status.html

295 lines
15 KiB
HTML
Raw Normal View History

2022-03-17 11:19:26 +01:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>connection_status</title>
<link rel="stylesheet" type="text/css" href="../../src/self.css">
<meta name="description" content="Liefert den internen Verbindungsstatus">
<meta name="keywords" content="SELFPHP, PHP, Sonstige-Funktionen, connection_status">
<meta name="author" content="Damir Enseleit, mail@selfphp.info">
<meta name="DC.Contributer" content="Matthias Hupp, m.hupp@selfphp3.de">
<meta name="DC.Publisher" content="Damir Enseleit, mail@selfphp.info">
<meta name="DC.Date" content="2001-08-22T12:18+01:00">
<meta name="DC.Identifier" content="http://www.selfphp3.de/funktionsreferenz/sonstige_funktionen/connection_status.html">
<meta name="DC.Language" content="de">
<meta name="DC.Rights" content="../../editorial/index.html">
<meta name="SELF.Firstdate" content="2001-08-22T12:18+01:00">
<meta name="SELF.Version" content="1">
<meta name="SELF.Pagetype" content="Information">
<meta name="SELF.Path" content="SELFPHP == ../../index.php // Funktionsreferenz == ../index.php // Sonstige-Funktionen == index.html">
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#AA5522" vlink="#772200" alink="#000000">
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td bgcolor="#FFEEDD" class="nav"><a class="an" name="top"><img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von"></a> <a href="../../index.html"><b>SELFPHP</b></a>/<a href="../../navigation/index.html">Navigationshilfen</a> <img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von"> <a href="../index.html"><b>Funktionsreferenz</b></a> <img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von"> <a href="index.html"><b>Sonstige-Funktionen</b></a></td>
</tr>
</table><table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td bgcolor="#EEEEEE" class="doc" width="110"><img src="../../src/logo.gif" width="106" height="109" border="0" alt="SEL.html"></td>
<td bgcolor="#EEEEEE" class="doc" valign="bottom" width="100%">
<h2>connection_status</h2>
<tr>
<td bgcolor="#EEEEEE" class="doc" valign="top" align="center">
<img src="../../src/dokx.gif" width="30" height="20" vspace="6" border="0" alt="Informationsseite">
</td>
<td bgcolor="#FFFFFF" valign="top" nowrap>
<p>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#befehl"><b>Befehl</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#version"><b>Version</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#beschreibung"><b>Beschreibung</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#beispiel1"><b>Beispiel1</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#ausgabe1"><b>Ausgabe1</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#beispiel2"><b>Beispiel2</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#ausgabe2"><b>Ausgabe2</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#beispiel3"><b>Beispiel3</b></a><br>
<img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten">&nbsp;<a href="#ausgabe3"><b>Ausgabe3</b></a><br>
</p>
</td>
</tr><tr><td colspan=2 bgcolor="#EEEEEE" class="doc"><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;</td></tr>
</table>
<h2 class="Sh2"><a class="an" name="befehl">Befehl</a></h2>
<table width="100%" cellpadding=10><tr>
<td class="xmpcode" bgcolor="#E4EEFF">int <b>connection_status</b>(void)</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="version">Version</a></h2>
<table width="100%" cellpadding=10 height="32">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF" height="20">
<p>PHP 3&gt;= 3.0.7, PHP 4 &gt;= 4.0b4</p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="beschreibung">Beschreibung</a></h2>
<table width="100%" cellpadding=10 height="572">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF" height="57">
<p>Mit connection_status() kann man sich den internen Verbindungsstatus
von PHP<br>
zur&uuml;ckgeben lassen.</p>
<p>Folgende drei (bzw. vier - siehe unten) Zustandsm&ouml;glichkeiten k&ouml;nnen
eintreten:<br>
0 - NORMAL<br>
1 - ABORTED<br>
2 - TIMEOUT<br>
3 - ABORTED und TIMEOUT</p>
<p>Ein aktives PHP-Skript hat normalerweise den Status NORMAL, es sei denn,<br>
dass durch irgendein Vorkommnis dieser Status ge&auml;ndert wird. Dabei
gibt es<br>
mehrere M&ouml;glichkeiten. Zum einen kann der User das laufende Skript
abbrechen<br>
und somit den Status auf ABORTED setzen, oder es kann vorkommen, dass
das<br>
Skript l&auml;nger l&auml;uft, als das eingestellte Zeitlimit zul&auml;sst
(Standard-Timeout in der<br>
Apache-Konfigurationsdatei ist 30 Sekunden, oder &uuml;ber set_time_limit()
eine<br>
vorgegebene Zeit). Bei &Uuml;berschreiten dieses Limits wird der Verbindungsstatus<br>
auf TIMEOUT gesetzt.<br>
Anhand dieser drei Werte kann man nun entscheiden, wie man mit diesem
Status<br>
umgehen m&ouml;chte. Oftmals will man gerade beim Abbruch durch den User
noch<br>
wichtige Daten retten.<br>
Beachten Sie bitte, dass die Funktion connection_status() gleichzeitig
den Staus<br>
ABORTED und TIMEOUT besitzen kann. Dies geschieht gerade dann, wenn<br>
man mit der Funkton ignore_user_abort() den Benutzerabbruch unterbindet.<br>
Dennoch kann es zu einem TIMEOUT kommen. In diesem Fall gibt die Funktion<br>
den Wert 3 (ABORTED + TIMEOUT) zur&uuml;ck, weil neben dem Timeout auch
der<br>
(folgenlose) Benutzerabbruch registriert wurde.</p>
<p>Siehe auch:</p>
<ul>
<li><a href="connection_aborted.html">connevtion_aborted()</a></li>
<li><a href="connection_timeout.html">connection_timeout()</a></li>
<li><a href="../functions_funktionen/register_shutdown_function.html">register_shutdown_function()</a></li>
</ul>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="beispiel1">Beispiel1</a></h2>
<table width="100%" cellpadding=10 height="66">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF">
<pre>&lt;?PHP<br>register_shutdown_function('countdown');<br>set_time_limit (10);<br>$produktseite = &quot;Monitore&quot;;<br>$produkt = &quot;17\&quot;-Monitor&quot;;<br>$zeit = date(&quot;l dS of F Y h:i:s A&quot;);<br>for($x=1;$x&lt;=55555555;$x++){<br> echo $x . &quot;&lt;br&gt;&quot;;<br>}<br>echo &quot;Ein simpler Shop&lt;br&gt;&quot;;<br>function countdown(){<br> $var = connection_status();<br> switch ($var) {<br> case 0:<br> echo &quot;Alles OK - weiter gehts!&quot;;<br> break;<br> case 1:<br> global $produktseite , $produkt , $zeit;<br> $werte = &quot;$produktseite||$produkt||$zeit\n&quot;; <br> $fp = fopen('statistik.txt','a');<br> fwrite($fp,$werte);<br> fclose($fp);<br> break;<br> case 2:<br> global $produktseite , $produkt , $zeit;<br> $werte = &quot;Timeout - $produktseite||$produkt||$zeit\n&quot;;<br> $fp = fopen('timeout.txt','a');<br> fwrite($fp,$werte);<br> fclose($fp);<br> break;<br> }<br>}<br>?&gt;</pre>
<p></p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="ausgabe1">Ausgabe1</a></h2>
<table width="100%" cellpadding=10 height="45">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF" height="57">
<p>1<br>
2<br>
3<br>
.<br>
.<br>
.<br>
51290<br>
51291</p>
<p><b>Fatal error:</b> Maximum execution time of 10 seconds exceeded in
<b>e:\apache\htdocs/php/index.php</b> on line <b>9<br>
<br>
<br>
</b>/*Inhalt der Datei zahlen.txt:<br>
Timeout - Monitore||17&quot;-Monitor||Monday 30th of July 2001 10:32:38
PM*/</p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="beispiel2">Beispiel2</a></h2>
<table width="100%" cellpadding=10 height="66">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF">
<pre>&lt;?PHP<br>register_shutdown_function('countdown');<br>$produktseite = &quot;Monitore&quot;;<br>$produkt = &quot;17\&quot;-Monitor&quot;;<br>$zeit = date(&quot;l dS of F Y h:i:s A&quot;);<br>for($x=1;$x&lt;=5;$x++){<br> echo $x . &quot;&lt;br&gt;&quot;;<br>}<br>echo &quot;Ein simpler Shop&lt;br&gt;&quot;;<br>function countdown(){<br> $var = connection_status();<br> switch ($var) {<br> case 0:<br> echo &quot;Alles OK - weiter gehts!&quot;;<br> break;<br> case 1:<br> global $produktseite , $produkt , $zeit;<br> $werte = &quot;$produktseite||$produkt|| $zeit\n&quot;; <br> $fp = fopen('statistik.txt','a');<br> fwrite($fp,$werte);<br> fclose($fp);<br> break;<br> case 2:<br> global $produktseite , $produkt , $zeit;<br> $werte = &quot;Timeout - $produktseite||$produkt||$zeit\n&quot;;
$fp = fopen('timeout.txt','a');<br> fwrite($fp,$werte);<br> fclose($fp);<br> break;<br> }<br>}<br>?&gt;</pre>
<p></p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="ausgabe2">Ausgabe2</a></h2>
<table width="100%" cellpadding=10 height="45">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF" height="57">
<p>1<br>
2<br>
3<br>
4<br>
5<br>
Ein simpler Shop<br>
Alles OK - weiter gehts!</p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="beispiel3">Beispiel3</a></h2>
<table width="100%" cellpadding=10 height="66">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF">
<pre>&lt;?PHP<br>// Wie Beispiel 1, allerdings ein Browserabbruch durch den User
//vor Verstreichen der 10 Sekunden<br>?&gt;</pre>
<p></p>
</td>
</tr></table>
<p>&nbsp;</p>
<table bgcolor="#EEEEEE" class="doc" width="100%"><tr><td>
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a><a href="#bottom"><img src="../../src/down.gif" width="14" height="10" border="0" alt="nach unten"></a>&#160;
</td></tr></table>
<h2 class="Sh2"><a class="an" name="ausgabe3">Ausgabe3</a></h2>
<table width="100%" cellpadding=10 height="45">
<tr>
<td class="xmpcode" bgcolor="#E4EEFF" height="57">
<p>1<br>
2<br>
3<br>
.<br>
.<br>
.<br>
26926<br>
26927<br>
26928<b><br>
<br>
<br>
</b>/*Inhalt der Datei zahlen.txt:<br>
Monitore||17&quot;-Monitor||Monday 30th of July 2001 10:30:15 PM*/</p>
</td>
</tr></table>
<p>&nbsp;</p>
<table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr><td colspan=2 bgcolor="#EEEEEE" class="doc">
<a href="#top"><img src="../../src/up.gif" width="14" height="10" border="0" alt="nach oben"></a>
</td></tr>
<tr>
<td bgcolor="#EEEEEE" class="doc" align="right" width="110">weiter:<a href="connection_timeout.html"><img src="../../src/next.gif" width="10" height="10" border="0" hspace="10" alt="weiter"></a></td>
<td bgcolor="#FFFFFF"><img src="../../src/dok.gif" width="15" height="10" border="0" alt="Seite">
<a href="connection_timeout.html"><b>connection_timeout</b></a> </td>
</tr>
<tr>
<td bgcolor="#EEEEEE" class="doc" align="right" width="110">zur&uuml;ck:<a href="connection_aborted.html"><img src="../../src/prev.gif" width="10" height="10" border="0" hspace="10" alt="zur&uuml;ck"></a></td>
<td bgcolor="#FFFFFF" width="100%"><img src="../../src/dok.gif" width="15" height="10" border="0" alt="Seite">
<a href="connection_aborted.html"><b>connection_aborted</b></a> </td>
</tr>
<tr><td colspan=2 bgcolor="#EEEEEE" class="doc">&#160;</td></tr>
</table><table cellpadding="4" cellspacing="0" border="0" width="100%">
<tr>
<td bgcolor="#FFEEDD" class="nav"><a class="an" name="bottom"><img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von"></a>
<a href="../../index.html"><b>SELFPHP</b></a>/<a href="../../navigation/index.html">Navigationshilfen</a> <img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von">
<a href="../index.html"><b>Funktionsreferenz</b></a> <img src="../../src/refkap.gif" width="16" height="13" border="0" alt="Teil von">
<a href="index.html"><b>Sonstige-Funktionen</b></a></td>
</tr>
</table>
<p><a class="an" name="bottom">&copy; 2001, 2002, 2003</A> <img src="../../src/mail.gif" width="15" height="10" border="0" alt="E-Mail">&nbsp;<a href="mailto:mail@selfphp.info">Damir Enseleit, mail@selfphp.info</a></p>
</body>
</html>