torben Fri Feb 1 16:19:24 2002 EDT
Modified files:
/phpdoc/en/functions sockets.xml
Log:
Fixed up the server example a bit.
Index: phpdoc/en/functions/sockets.xml
diff -u phpdoc/en/functions/sockets.xml:1.30 phpdoc/en/functions/sockets.xml:1.31
--- phpdoc/en/functions/sockets.xml:1.30 Wed Jan 9 11:51:46 2002
+++ phpdoc/en/functions/sockets.xml Fri Feb 1 16:19:23 2002
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
-<!-- $Revision: 1.30 $ -->
+<!-- $Revision: 1.31 $ -->
<reference id="ref.sockets">
<title>Socket functions</title>
<titleabbrev>Sockets</titleabbrev>
@@ -49,6 +49,7 @@
</para>
<programlisting role="php">
<![CDATA[
+#!/usr/local/bin/php -q
<?php
error_reporting (E_ALL);
@@ -75,17 +76,23 @@
echo "socket_accept() failed: reason: " . socket_strerror ($msgsock) . "\n";
break;
}
+ /* Send instructions. */
+ $msg = "\nWelcome to the PHP Test Server. \n" .
+ "To quit, type 'quit'. To shut down the server type 'shutdown'.\n";
+ socket_write($msgsock, $msg, strlen($msg));
+
do {
- $buf = socket_read ($msgsock, 2048);
- if ($buf == FALSE) {
+ if (FALSE === ($buf = socket_read ($msgsock, 2048))) {
echo "socket_read() failed: reason: " . socket_strerror ($ret) . "\n";
break 2;
}
- if (!$buf) {
- break 2;
+ if (!$buf = trim ($buf)) {
+ continue;
}
- $buf = trim ($buf);
if ($buf == 'quit') {
+ break;
+ }
+ if ($buf == 'shutdown') {
socket_close ($msgsock);
break 2;
}
@@ -128,7 +135,7 @@
if ($socket < 0) {
echo "socket_create() failed: reason: " . socket_strerror ($socket) . "\n";
} else {
- "socket_create() successful: " . socket_strerror ($socket) . "\n";
+ echo "OK.\n";
}
echo "Attempting to connect to '$address' on port '$service_port'...";