irchtml Wed Feb 25 01:04:51 2004 EDT
Modified files:
/phpdoc/en/reference/sockets/functions socket-create-pair.xml
Log:
fixed example (missing a few closing parens) per user note
http://cvs.php.net/diff.php/phpdoc/en/reference/sockets/functions/socket-create-pair.xml?r1=1.4&r2=1.5&ty=u
Index: phpdoc/en/reference/sockets/functions/socket-create-pair.xml
diff -u phpdoc/en/reference/sockets/functions/socket-create-pair.xml:1.4
phpdoc/en/reference/sockets/functions/socket-create-pair.xml:1.5
--- phpdoc/en/reference/sockets/functions/socket-create-pair.xml:1.4 Sun Jan 18
15:27:32 2004
+++ phpdoc/en/reference/sockets/functions/socket-create-pair.xml Wed Feb 25
01:04:50 2004
@@ -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 @@
$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";
+ }
}
?>
]]>