Sample code for 30+ languages & platforms
PHP

Duplicate a Socket Wrapper Sharing the Connection

See more Socket/SSL/TLS Examples

Demonstrates Socket.DupSocket, which populates a destination Socket with another wrapper that shares this object's underlying connection.

Background. The shared connection is reference-counted, and all wrappers operate on the same live connection. The destination first releases any connection it previously held.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Socket;

$socket = new Socket();

// Connect to the server using TLS.
$bTls = true;
$maxWaitMs = 5000;
try {
    $socket->Connect('example.com', 5000, $bTls, $maxWaitMs);

    // Create a second Socket wrapper that shares this object's underlying connection.  Both wrappers
    // operate on the same live connection; the shared connection is reference-counted.
    $dupSock = new Socket();
    $socket->DupSocket($dupSock);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo "Duplicate socket wrapper created.\n";