fixed example (missing a few closing parens) per user note

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@152300 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Kenneth Schwartz 2004-02-25 06:04:50 +00:00
parent 2d9c4be21f
commit b4a4dfe159

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.4 $ -->
<!-- $Revision: 1.5 $ -->
<!-- splitted from ./en/functions/sockets.xml, last change in rev 1.27 -->
<refentry id="function.socket-create-pair">
<refnamediv>
@ -174,21 +174,21 @@
<![CDATA[
<?php
$sockets = array();
$uniqid = uniqid("");
if (file_exists("/tmp/$uniqid.sock"))
$uniqid = uniqid('');
if (file_exists("/tmp/$uniqid.sock")) {
die('Temporary socket already exists.');
}
/* Setup socket pair */
if(!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets))
if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets)) {
echo socket_strerror(socket_last_error());
}
/* Send and Recieve Data */
if(!socket_write($sockets[0], "ABCdef123\n", strlen("ABCdef123\n")))
if (!socket_write($sockets[0], "ABCdef123\n", strlen("ABCdef123\n"))) {
echo socket_strerror(socket_last_error());
if(!$data = socket_read($sockets[1], strlen("ABCdef123\n"), PHP_BINARY_READ))
}
if (!$data = socket_read($sockets[1], strlen("ABCdef123\n"), PHP_BINARY_READ)) {
echo socket_strerror(socket_last_error());
}
var_dump($data);
/* Close sockets */
@ -208,27 +208,30 @@ socket_close($sockets[1]);
$ary = array();
$strone = 'Message From Parent.';
$strtwo = 'Message From Child.';
if(!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary))
if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary)) {
echo socket_strerror(socket_last_error());
}
$pid = pcntl_fork();
if($pid == -1)
{
if ($pid == -1) {
echo 'Could not fork Process.';
} elseif( $pid ) {
} elseif ($pid) {
/*parent*/
socket_close($ary[0]);
if(!socket_write($ary[1], $strone, strlen($strone))
if (!socket_write($ary[1], $strone, strlen($strone))) {
echo socket_strerror(socket_last_error());
if(socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo)
echo 'Recieved ', $strtwo;
}
if (socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo) {
echo "Recieved $strtwo\n";
}
} else {
/*child*/
socket_close($ary[1]);
if(!socket_write($ary[0], $strtwo, strlen($strtwo))
if (!socket_write($ary[0], $strtwo, strlen($strtwo))) {
echo socket_strerror(socket_last_error());
if(socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone)
echo 'Recieved ', $strone;
}
if (socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone) {
echo "Recieved $strone\n";
}
}
?>
]]>