mirror of
https://github.com/php/doc-ja.git
synced 2026-03-24 07:02:08 +01:00
221 lines
7.0 KiB
XML
221 lines
7.0 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- $Revision$ -->
|
||
<!-- EN-Revision: 14dc7c47365f2b71f6c907a5ba5bccf42534d5a9 Maintainer: hirokawa Status: ready -->
|
||
<!-- CREDITS: takagi,mumumu -->
|
||
<refentry xml:id="function.socket-create-pair" xmlns="http://docbook.org/ns/docbook">
|
||
<refnamediv>
|
||
<refname>socket_create_pair</refname>
|
||
<refpurpose>区別できないソケットの組を作成し、配列に保存する</refpurpose>
|
||
</refnamediv>
|
||
|
||
<refsect1 role="description">
|
||
&reftitle.description;
|
||
<methodsynopsis>
|
||
<type>bool</type><methodname>socket_create_pair</methodname>
|
||
<methodparam><type>int</type><parameter>domain</parameter></methodparam>
|
||
<methodparam><type>int</type><parameter>type</parameter></methodparam>
|
||
<methodparam><type>int</type><parameter>protocol</parameter></methodparam>
|
||
<methodparam><type>array</type><parameter role="reference">pair</parameter></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
<function>socket_create_pair</function> は、接続されており区別できない
|
||
2 つのソケットを作成し、それを <parameter>pair</parameter> に保存します。
|
||
この関数は、一般に IPC(InterProcess Communication: プロセス間通信)
|
||
で使用します。
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="parameters">
|
||
&reftitle.parameters;
|
||
<para>
|
||
<variablelist>
|
||
<varlistentry>
|
||
<term><parameter>domain</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
<parameter>domain</parameter> は、ソケットで使用するプロトコルの種類を指定します。
|
||
完全な一覧は <function>socket_create</function> を参照ください。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>type</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
<parameter>type</parameter> では、ソケットが使用する通信の形式を選択します。
|
||
完全な一覧は <function>socket_create</function> を参照ください。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>protocol</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
<parameter>protocol</parameter> は、指定した <parameter>domain</parameter>
|
||
の中の特定のプロトコルを指定します。これは、返されるソケットとの通信に使用されます。
|
||
使用可能な値の名前は <function>getprotobyname</function>
|
||
で取得可能です。もし要求されるプロトコルが TCP あるいは UDP の場合、
|
||
対応する定数 <constant>SOL_TCP</constant> および <constant>SOL_UDP</constant>
|
||
も使用可能です。
|
||
</para>
|
||
<para>
|
||
サポートするプロトコルの完全な一覧は <function>socket_create</function> を参照ください。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
<varlistentry>
|
||
<term><parameter>pair</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
2 つの <classname>Socket</classname> クラスのインスタンスが格納される配列への参照。
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
</variablelist>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="returnvalues">
|
||
&reftitle.returnvalues;
|
||
<para>
|
||
&return.success;
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="changelog">
|
||
&reftitle.changelog;
|
||
<informaltable>
|
||
<tgroup cols="2">
|
||
<thead>
|
||
<row>
|
||
<entry>&Version;</entry>
|
||
<entry>&Description;</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry>8.0.0</entry>
|
||
<entry>
|
||
<parameter>pair</parameter> は、
|
||
<classname>Socket</classname> クラスのインスタンスの配列へのリファレンスになりました。
|
||
これより前のバージョンでは、リソースの配列へのリファレンスでした。
|
||
</entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</informaltable>
|
||
</refsect1>
|
||
|
||
<refsect1 role="examples">
|
||
&reftitle.examples;
|
||
<para>
|
||
<example>
|
||
<title><function>socket_create_pair</function> の例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$sockets = array();
|
||
|
||
/* Windows では AF_INET を使う必要があります */
|
||
$domain = (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN' ? AF_INET : AF_UNIX);
|
||
|
||
/* ソケットの組の設定 */
|
||
if (socket_create_pair($domain, SOCK_STREAM, 0, $sockets) === false) {
|
||
echo "socket_create_pair failed. Reason: ".socket_strerror(socket_last_error());
|
||
}
|
||
/* データの送受信 */
|
||
if (socket_write($sockets[0], "ABCdef123\n", strlen("ABCdef123\n")) === false) {
|
||
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($sockets[0]));
|
||
}
|
||
if (($data = socket_read($sockets[1], strlen("ABCdef123\n"), PHP_BINARY_READ)) === false) {
|
||
echo "socket_read() failed. Reason: ".socket_strerror(socket_last_error($sockets[1]));
|
||
}
|
||
var_dump($data);
|
||
|
||
/* ソケットのクローズ */
|
||
socket_close($sockets[0]);
|
||
socket_close($sockets[1]);
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title><function>socket_create_pair</function> での IPC の例</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
$ary = array();
|
||
$strone = 'Message From Parent.';
|
||
$strtwo = 'Message From Child.';
|
||
|
||
if (socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary) === false) {
|
||
echo "socket_create_pair() failed. Reason: ".socket_strerror(socket_last_error());
|
||
}
|
||
$pid = pcntl_fork();
|
||
if ($pid == -1) {
|
||
echo 'プロセスを fork できません。';
|
||
} elseif ($pid) {
|
||
/* 親プロセス */
|
||
socket_close($ary[0]);
|
||
if (socket_write($ary[1], $strone, strlen($strone)) === false) {
|
||
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[1]));
|
||
}
|
||
if (socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo) {
|
||
echo "Received $strtwo\n";
|
||
}
|
||
socket_close($ary[1]);
|
||
} else {
|
||
/* 子プロセス */
|
||
socket_close($ary[1]);
|
||
if (socket_write($ary[0], $strtwo, strlen($strtwo)) === false) {
|
||
echo "socket_write() failed. Reason: ".socket_strerror(socket_last_error($ary[0]));
|
||
}
|
||
if (socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone) {
|
||
echo "Received $strone\n";
|
||
}
|
||
socket_close($ary[0]);
|
||
}
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="seealso">
|
||
&reftitle.seealso;
|
||
<para>
|
||
<simplelist>
|
||
<member><function>socket_create</function></member>
|
||
<member><function>socket_create_listen</function></member>
|
||
<member><function>socket_bind</function></member>
|
||
<member><function>socket_listen</function></member>
|
||
<member><function>socket_last_error</function></member>
|
||
<member><function>socket_strerror</function></member>
|
||
</simplelist>
|
||
</para>
|
||
</refsect1>
|
||
</refentry>
|
||
<!-- Keep this comment at the end of the file
|
||
Local variables:
|
||
mode: sgml
|
||
sgml-omittag:t
|
||
sgml-shorttag:t
|
||
sgml-minimize-attributes:nil
|
||
sgml-always-quote-attributes:t
|
||
sgml-indent-step:1
|
||
sgml-indent-data:t
|
||
indent-tabs-mode:nil
|
||
sgml-parent-document:nil
|
||
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||
sgml-exposed-tags:nil
|
||
sgml-local-catalogs:nil
|
||
sgml-local-ecat-files:nil
|
||
End:
|
||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
vim: et tw=78 syn=sgml
|
||
vi: ts=1 sw=1
|
||
-->
|