PHPackages                             wyrihaximus/react-opportunistic-tls - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. wyrihaximus/react-opportunistic-tls

ActiveLibrary[HTTP &amp; Networking](/categories/http)

wyrihaximus/react-opportunistic-tls
===================================

1.0.2(3mo ago)35.7k—4.6%1[2 issues](https://github.com/WyriHaximus/reactphp-opportunistic-tls/issues)[3 PRs](https://github.com/WyriHaximus/reactphp-opportunistic-tls/pulls)1MITPHPPHP &gt;=7.0.0CI passing

Since Jun 10Pushed 1w ago1 watchersCompare

[ Source](https://github.com/WyriHaximus/reactphp-opportunistic-tls)[ Packagist](https://packagist.org/packages/wyrihaximus/react-opportunistic-tls)[ GitHub Sponsors](https://github.com/WyriHaximus)[ RSS](/packages/wyrihaximus-react-opportunistic-tls/feed)WikiDiscussions main Synced 4d ago

READMEChangelog (3)Dependencies (16)Versions (8)Used By (1)

Opportunistic TLS for ReactPHP
==============================

[](#opportunistic-tls-for-reactphp)

[![Continuous Integration](https://github.com/WyriHaximus/reactphp-opportunistic-tls/workflows/Continuous%20Integration/badge.svg)](https://github.com/WyriHaximus/reactphp-opportunistic-tls/workflows/Continuous%20Integration/badge.svg)[![Latest Stable Version](https://camo.githubusercontent.com/d8baecb2e40649cba0f15eea30144fffc02a611673cd5329c002ea731fe76b21/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d6f70706f7274756e69737469632d746c732f762f737461626c652e706e67)](https://packagist.org/packages/WyriHaximus/react-opportunistic-tls)[![Total Downloads](https://camo.githubusercontent.com/d1143475eca556ccf3181e73aaee27e89a31c30cbbaff01e346434b441faf46a/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d6f70706f7274756e69737469632d746c732f646f776e6c6f6164732e706e67)](https://packagist.org/packages/WyriHaximus/react-opportunistic-tls)[![License](https://camo.githubusercontent.com/19f3c4d5a6ce939ee83cb0e98a658955eda338676948b054a9171e7729adbbeb/68747470733a2f2f706f7365722e707567782e6f72672f57797269486178696d75732f72656163742d6f70706f7274756e69737469632d746c732f6c6963656e73652e706e67)](https://packagist.org/packages/WyriHaximus/react-opportunistic-tls)

Install
=======

[](#install)

To install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.

```
composer require wyrihaximus/react-opportunistic-tls

```

Usage
=====

[](#usage)

Because this package is extracted from [this PR](https://github.com/reactphp/socket/pull/302) the API is identical as to proposed there. Making it a two line change in any packages using this package once the PR has been merged. We, the ReactPHP core team, decided on going with testing it out in a package before merging in the PR. Main reasons ensuring we tackle most unexpected issues as this is a tricky subject. This package is set up as a drop in replacement for the `Connector` and `SocketServer`. Put `WyriHaximus\` in front of its namespace to use it.

Client
------

[](#client)

```
use WyriHaximus\React\Socket;

use function React\Promise\Stream\first;

$connector = new Socket\Connector();
$connector->connect('opportunistic+tls://example.com:5432/')->then(function (Socket\OpportunisticTlsConnectionInterface $startTlsConnection) {
    $connection->write('let\'s encrypt?');

    return first($connection)->then(function ($data) use ($connection) {
        if ($data === 'yes') {
            return $connection->enableEncryption();
        }

        return $stream;
    });
})->then(function (Socket\ConnectionInterface $connection) {
    $connection->write('Hello!');
});
```

Server
------

[](#server)

```
use WyriHaximus\React\Socket;

$socket = new Socket\SocketServer('opportunistic+tls://127.0.0.1:8000', array(
    'tls' => array(
        'local_cert' => 'server.pem',
        'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER
    )
));
$server->on('connection', static function (Socket\OpportunisticTlsConnectionInterface $connection) use ($server) {
    return $connection->enableEncryption();
});
```

License
=======

[](#license)

The MIT License (MIT)

Copyright (c) 2025 Cees-Jan Kiewiet

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance76

Regular maintenance activity

Popularity29

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~117 days

Total

3

Last Release

116d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/147145?v=4)[Cees-Jan Kiewiet](/maintainers/WyriHaximus)[@WyriHaximus](https://github.com/WyriHaximus)

---

Top Contributors

[![WyriHaximus](https://avatars.githubusercontent.com/u/147145?v=4)](https://github.com/WyriHaximus "WyriHaximus (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (9 commits)")[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (2 commits)")

### Embed Badge

![Health badge](/badges/wyrihaximus-react-opportunistic-tls/health.svg)

```
[![Health](https://phpackages.com/badges/wyrihaximus-react-opportunistic-tls/health.svg)](https://phpackages.com/packages/wyrihaximus-react-opportunistic-tls)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.3k](/packages/friendsofphp-php-cs-fixer)[ccxt/ccxt

A cryptocurrency trading API with more than 100 exchanges in JavaScript / TypeScript / Python / C# / PHP / Go

43.2k341.0k1](/packages/ccxt-ccxt)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78127.7M466](/packages/react-http)[team-reflex/discord-php

An unofficial API to interact with the voice and text service Discord.

1.1k420.9k26](/packages/team-reflex-discord-php)[clue/docker-react

Async, event-driven access to the Docker Engine API, built on top of ReactPHP.

113163.3k1](/packages/clue-docker-react)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
