mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Fixed up the server example a bit.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@69231 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
7ef5a787ae
commit
78e335aeb6
1 changed files with 14 additions and 7 deletions
|
@ -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 @@ do {
|
|||
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 @@ $socket = socket_create (AF_INET, SOCK_STREAM, 0);
|
|||
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'...";
|
||||
|
|
Loading…
Reference in a new issue