П О Р Т А Л                            
С Е Т Е В Ы Х                          
П Р О Е К Т О В                        
Поиск по сайту:

О проекте

     HTML & JavaScript
     XML & XSLT
     Unix Shell





Самое читаемое:

Учебник PHP - "Для Чайника".
Просмотров 864 раз(а).

Иллюстрированный самоучитель по созданию сайтов.
Просмотров 94639 раз(а).

Учебник HTML.
Просмотров 81932 раз(а).

Руководство по PHP5.
Просмотров 52352 раз(а).

Хостинг через призму DNS.
Просмотров 60999 раз(а).

Подборка текстов стандартных документов.
Просмотров 50861 раз(а).

Учебник PHP - Самоучитель
Просмотров 58203 раз(а).

Документация на MySQL (учебник & справочное руководство)
Просмотров 59723 раз(а).

Внешние атаки...
Просмотров 49460 раз(а).

Учебник PHP.
Просмотров 42696 раз(а).

SSI в примерах.
Просмотров 32948 раз(а).

| Добавить в избранное | Сделать стартовой | Помощь

Руководство по PHP
Пред. След.


(PHP 4 >= 4.1.0, PHP 5)

socket_create_pair -- Creates a pair of indistinguishable sockets and stores them in an array


bool socket_create_pair ( int domain, int type, int protocol, array &fd )

socket_create_pair() creates two connected and indistinguishable sockets, and stores them in fd. This function is commonly used in IPC (InterProcess Communication).

The domain parameter specifies the protocol family to be used by the socket.

Таблица 1. Available address/protocol families

AF_INET IPv4 Internet based protocols. TCP and UDP are common protocols of this protocol family. Supported only in windows.
AF_INET6 IPv6 Internet based protocols. TCP and UDP are common protocols of this protocol family. Support added in PHP 5.0.0. Supported only in windows.
AF_UNIX Local communication protocol family. High efficiency and low overhead make it a great form of IPC (Interprocess Communication).

The type parameter selects the type of communication to be used by the socket.

Таблица 2. Available socket types

SOCK_STREAM Provides sequenced, reliable, full-duplex, connection-based byte streams. An out-of-band data transmission mechanism may be supported. The TCP protocol is based on this socket type.
SOCK_DGRAM Supports datagrams (connectionless, unreliable messages of a fixed maximum length). The UDP protocol is based on this socket type.
SOCK_SEQPACKET Provides a sequenced, reliable, two-way connection-based data transmission path for datagrams of fixed maximum length; a consumer is required to read an entire packet with each read call.
SOCK_RAW Provides raw network protocol access. This special type of socket can be used to manually construct any type of protocol. A common use for this socket type is to perform ICMP requests (like ping, traceroute, etc).
SOCK_RDM Provides a reliable datagram layer that does not guarantee ordering. This is most likely not implemented on your operating system.

The protocol parameter sets the specific protocol within the specified domain to be used when communicating on the returned socket. The proper value can be retrieved by name by using getprotobyname(). If the desired protocol is TCP, or UDP the corresponding constants SOL_TCP, and SOL_UDP can also be used.

Таблица 3. Common protocols

icmp The Internet Control Message Protocol is used primarily by gateways and hosts to report errors in datagram communication. The "ping" command (present in most modern operating systems) is an example application of ICMP.
udp The User Datagram Protocol is a connectionless, unreliable, protocol with fixed record lengths. Due to these aspects, UDP requires a minimum amount of protocol overhead.
tcp The Transmission Control Protocol is a reliable, connection based, stream oriented, full duplex protocol. TCP guarantees that all data packets will be received in the order in which they were sent. If any packet is somehow lost during communication, TCP will automatically retransmit the packet until the destination host acknowledges that packet. For reliability and performance reasons, the TCP implementation itself decides the appropriate octet boundaries of the underlying datagram communication layer. Therefore, TCP applications must allow for the possibility of partial record transmission.

Пример 1. socket_create_pair() example

= array();
/* Setup socket pair */
if (!socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $sockets)) {
/* Send and Recieve Data */
if (!socket_write($sockets[0], "ABCdef123\n", strlen("ABCdef123\n"))) {
if (!
$data = socket_read($sockets[1], strlen("ABCdef123\n"), PHP_BINARY_READ)) {

/* Close sockets */

Пример 2. socket_create_pair() IPC example

= array();
$strone = 'Message From Parent.';
$strtwo = 'Message From Child.';
if (!
socket_create_pair(AF_UNIX, SOCK_STREAM, 0, $ary)) {
$pid = pcntl_fork();
if (
$pid == -1) {
'Could not fork Process.';
} elseif (
$pid) {
    if (!
socket_write($ary[1], $strone, strlen($strone))) {
    if (
socket_read($ary[1], strlen($strtwo), PHP_BINARY_READ) == $strtwo) {
"Recieved $strtwo\n";
} else {
    if (!
socket_write($ary[0], $strtwo, strlen($strtwo))) {
    if (
socket_read($ary[0], strlen($strone), PHP_BINARY_READ) == $strone) {
"Recieved $strone\n";

Пред. Начало След.
socket_create_listen Уровень выше socket_create

Если Вы не нашли что искали, то рекомендую воспользоваться поиском по сайту:

Copyright © 2005-2016 Project.Net.Ru