Skip to content

yidas/php-socket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php Socket

Modern PHP Socket class based on native infra (pure PHP, CI, Yii, Laravel support)

Latest Stable Version License

DEMONSTRATION

Client

try {

    $socket = new \yidas\socket\Client([
        'protocol' => 'tcp',
        'host' => 'smtp.your.com',
        'port' => '25',
        // 'domain' => AF_INET,
    ]);

} catch (Exception $e) {
    
    die("Failed to connect: {$e->getMessage()} (Code: {$e->getCode()})");
}

echo $socket->read();
// ...
$socket->write('STARTTLS');
echo $socket->read();
$result = $socket->enableCrypto();
// ...

$socket->close();

Native function support:

$socket = new \yidas\socket\Client();

try {

  $socket->stream_socket_client('tcp://smtp.your.com:25', $errorCode, $errorMsg, 15);

} catch (Exception $e) {
    
    die("Failed to connect: {$e->getMessage()} (Code: {$e->getCode()})");
}

$socket->fread(1024);
// ...
$socket->fwrite('STARTTLS');
echo $socket->fread(1024);
$result = $socket->stream_socket_enable_crypto(true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT);
// ...

$socket->fclose();

About

Developing

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages