stream_socket_pair

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

stream_socket_pair Creates a pair of connected, indistinguishable socket streams

Beschreibung

stream_socket_pair(int $domain, int $type, int $protocol): array|false

stream_socket_pair() creates a pair of connected, indistinguishable socket streams. This function is commonly used in IPC (Inter-Process Communication).

Parameter-Liste

domain

The protocol family to be used: STREAM_PF_INET, STREAM_PF_INET6 or STREAM_PF_UNIX

type

The type of communication to be used: STREAM_SOCK_DGRAM, STREAM_SOCK_RAW, STREAM_SOCK_RDM, STREAM_SOCK_SEQPACKET or STREAM_SOCK_STREAM

protocol

The protocol to be used: STREAM_IPPROTO_ICMP, STREAM_IPPROTO_IP, STREAM_IPPROTO_RAW, STREAM_IPPROTO_TCP or STREAM_IPPROTO_UDP

Hinweis: Please consult the Streams constant list for further details on each constant.

Rückgabewerte

Returns an array with the two socket resources on success, or false on failure.

Beispiele

Beispiel #1 A stream_socket_pair() example

This example shows the basic usage of stream_socket_pair() in Inter-Process Communication.

<?php

$sockets 
stream_socket_pair(STREAM_PF_UNIXSTREAM_SOCK_STREAMSTREAM_IPPROTO_IP);
$pid     pcntl_fork();

if (
$pid == -1) {
     die(
'could not fork');

} else if (
$pid) {
     
/* parent */
    
fclose($sockets[0]);

    
fwrite($sockets[1], "child PID: $pid\n");
    echo 
fgets($sockets[1]);

    
fclose($sockets[1]);

} else {
    
/* child */
    
fclose($sockets[1]);

    
fwrite($sockets[0], "message from child\n");
    echo 
fgets($sockets[0]);

    
fclose($sockets[0]);
}

?>

Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:

child PID: 1378
message from child

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Warning: Undefined variabl

Your article presents comprehensive and comprehensible information. I gained knowledge from this article that I had previously lacked. While I gen ...

Geschrieben von poppy12 am 30.05.2024 09:58:23
Forum: PHP Developer Forum
PHP 8.3.3 - App kann auf dem PC nicht ausgeführt werden

Many thanks for the valuable information you provide. In the future, I hope you will continue to provide everyone with as many excellent postings ...

Geschrieben von poppy12 am 30.05.2024 09:56:42
Forum: PHP Developer Forum
Schleifenproblem für MYSQL mit gleichen INPUT Feldnamen

This one-of-a-kind game has sparked a lot of attention. In poppy playtime (https://poppy-playtime.io), you must visit the Playtime toy factory. Th ...

Geschrieben von poppy12 am 30.05.2024 09:54:26
Forum: PHP Developer Forum
Seite neu Laden

Thank you very much for the excellent information you provided. In the future, I hope you will continue to provide everyone with as many fantastic ...

Geschrieben von dordle2 am 30.05.2024 09:52:03
Forum: Fragen/Vorschläge zum Forum