PHP-Fusion
v.7.01
AP-Fusion
v7.02.05
Pimped-Fusion-AP
v0.09.03
April 19 2024 14:37:50
Авторизация
Логин

Пароль



Вы не зарегистрированы?
Нажмите здесь для регистрации.

Забыли пароль?
Запросите новый здесь.
Мини-чат
Вы должны авторизироваться, чтобы добавить сообщение.

lom
06/04/2018 14:03
Мы рады, ждем девятку. Очень хочется пощупать

Alipapa
27/03/2018 22:16
Всем привет, все неисправности устранили, всё у нас работает

mukaton
30/10/2015 02:37
Не получается ничего скачать. Ошибка Not Found

Alipapa
06/10/2015 23:00
9-я версия php-fusion на подходе, следите за новостями

Alipapa
10/11/2014 11:24
Заметь, я дважды ответил через 3 минуты после вопроса, могли бы уже решить

Последние статьи
· О стабилизаторах нап...
· СМС и Вебмани
· TinyMCE для пользова...
· PCRE (Perl Compatibl...
· PCRE (Perl Compatibl...
Последние активные темы форума
  Темы Просмотров Ответов Последние сообщения
PHP-Fusion 7 Bogatyr - бесп...
Моды, плагины
7133 1 Vveb--ws
08-10-2018 16:47
Php-Fusion v9. Первые впеча...
Вопросы по работе
4506 3 Vveb--ws
25-07-2018 13:46
Появился хэлп по PHP-Fusion...
Вопросы по работе
6735 7 Vveb--ws
25-07-2018 13:42
prestashop&ap-fusion
Вопросы по работе
17341 61 Alipapa
26-08-2014 10:29
Плагин магазина Ap-Shop
Моды, плагины
14586 70 Alipapa
18-08-2014 18:14
TinyMCE
Вопросы по работе
21100 55 Alipapa
27-07-2013 21:57
HTML-5
Моды, плагины
5431 1 Alipapa
15-06-2013 19:47
Мультиязычность в Pimped-Fu...
Ошибки, баги, глюки
6259 4 Papich
16-04-2013 12:39
Pimped-Fusion. Первые впеча...
Ошибки, баги, глюки
21694 127 Alipapa
18-12-2012 10:59
Ищу мод для расстановки код...
Моды, плагины
14999 55 Alipapa
17-09-2012 14:00
Как присоединить файл к лич...
Моды, плагины
8259 3 lom
27-05-2012 18:12
Что мне не нравится в после...
Вопросы по работе
6846 4 Alipapa
27-05-2012 18:08
Проблемы с добавлением кате...
Вопросы по работе
7741 5 Alipapa
27-05-2012 18:06

socket_create_pair

(PHP 4 >= 4.1.0, PHP 5)

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

Description

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

DomainDescription
AF_INETIPv4 Internet based protocols. TCP and UDP are common protocols of this protocol family. Supported only in windows.
AF_INET6IPv6 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_UNIXLocal 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

TypeDescription
SOCK_STREAMProvides 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_DGRAMSupports datagrams (connectionless, unreliable messages of a fixed maximum length). The UDP protocol is based on this socket type.
SOCK_SEQPACKETProvides 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_RAWProvides 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_RDMProvides 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

NameDescription
icmpThe 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.
udpThe User Datagram Protocol is a connectionless, unreliable, protocol with fixed record lengths. Due to these aspects, UDP requires a minimum amount of protocol overhead.
tcpThe 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

<?php
$sockets
= array();
$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 )) {
    echo
socket_strerror ( socket_last_error ());
}
/* Send and Recieve Data */
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 )) {
    echo
socket_strerror ( socket_last_error ());
}
var_dump ( $data );

/* Close sockets */
socket_close ( $sockets [ 0 ]);
socket_close ( $sockets [ 1 ]);
?>

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

<?php
$ary
= array();
$strone = 'Message From Parent.' ;
$strtwo = 'Message From Child.' ;
if (!
socket_create_pair ( AF_UNIX , SOCK_STREAM , 0 , $ary )) {
    echo
socket_strerror ( socket_last_error ());
}
$pid = pcntl_fork ();
if (
$pid == - 1 ) {
    echo
'Could not fork Process.' ;
} elseif (
$pid ) {
    
/*parent*/
    
socket_close ( $ary [ 0 ]);
    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 \n " ;
    }
    
socket_close ( $ary [ 1 ]);
} else {
    
/*child*/
    
socket_close ( $ary [ 1 ]);
    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 \n " ;
    }
    
socket_close ( $ary [ 0 ]);
}
?>

Все функции PHP:
Навигация
· Новости
· Статьи
· Скачать
· Форум
· Ссылки
· Категории новостей
· Обратная связь
· Галерея
· Поиск
· CMS AP-Fusion. Отличия от PHP-Fusion
· Javascript справочник
· Техника
Сейчас на сайте
· Гостей: 1

· Пользователей: 0

· Всего пользователей: 453
· Новый пользователь: ZDA
Информеры
Загрузка файлов  +  -
9,934,933 уникальных посетителей Iceberg by Harly