PHPackages                             originphp/socket - 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. originphp/socket

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

originphp/socket
================

OriginPHP Socket

2.0.0(5y ago)14.9k↓25%MITPHPPHP &gt;=7.3.0

Since Oct 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/originphp/socket)[ Packagist](https://packagist.org/packages/originphp/socket)[ Docs](https://www.originphp.com)[ RSS](/packages/originphp-socket/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Socket
======

[](#socket)

[![license](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)](https://camo.githubusercontent.com/6fdb99389fe9d9e8a5c197002a191ace7c8b12a2020c0fa5756cf17aa08a4966/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874477265656e2e737667)[![build](https://github.com/originphp/socket/workflows/CI/badge.svg)](https://github.com/originphp/socket/actions)[![coverage](https://camo.githubusercontent.com/e8cfc183dd39bd1db80a8103873306491a25b4d5b8666cf38feece7fdd88a70e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6f726967696e7068702f736f636b65742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/originphp/socket?branch=master)

The `Socket` class is a lightweight wrapper which makes working with sockets easy.

Installation
------------

[](#installation)

To install this package

```
$ composer require originphp/socket

```

Using Sockets
-------------

[](#using-sockets)

```
use Origin\Socket\Socket;
$socket = new Socket([
    'host' => 'localhost',
    'protocol' => 'tcp',
    'port' => 25,
    'timeout' => 30,
    'persistent' => false,
]);

if ($socket->connect()) {
    $socket->write("HELO mydomain.com\r\n");
    $result = $socket->read();
}

$socket->disconnect();
```

You can can also enable encryption using `ssl` or `tls`, you can also specify versions e.g. `sslv2`, `sslv23`, `sslv3`, `tlsv1`, `tlsv11` and `tlsv12`. See the [PHP manual](https://www.php.net/manual/en/function.stream-socket-enable-crypto.php) for more information on the encryption methods.

To enable encryption

```
$socket->enableEncryption('tls');
$socket->enableEncryption('ssl');
```

To disable encryption

```
$socket->disableEncryption('tls');
$socket->disableEncryption('ssl');
```

Host/IP Address
---------------

[](#hostip-address)

To get the IP address of the connection

```
$ipAddress = $socket->address();
```

To get the hostname

```
$hostname = $socket->host();
```

Stream Contexts
---------------

[](#stream-contexts)

When creating a Socket you can also provide `context` options that will be used to create a [stream context](https://www.php.net/manual/en/function.stream-context-create.php).

```
$socket = new Socket([
    'host' => 'example.com',
    'protocol' => 'tcp',
    'port' => 443,
    'timeout' => 30,
    'persistent' => false,
    'context' => [
        'ssl' => [
            'verify_peer' => false
        ]
    ]
]);
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~148 days

Total

4

Last Release

1960d ago

Major Versions

1.0.2 → 2.0.02021-01-04

PHP version history (3 changes)1.0.0PHP ^7.2.0

1.0.2PHP &gt;=7.2.0

2.0.0PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e8a821333d9c7b7bc2ad3d164d142f65cd3912dea78033d31f76b0f19ba8a0c?d=identicon)[originphp](/maintainers/originphp)

---

Top Contributors

[![jamielsharief](https://avatars.githubusercontent.com/u/20553479?v=4)](https://github.com/jamielsharief "jamielsharief (18 commits)")

---

Tags

streamtlsSocketssloriginPHP

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/originphp-socket/health.svg)

```
[![Health](https://phpackages.com/badges/originphp-socket/health.svg)](https://phpackages.com/packages/originphp-socket)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.0B3.2k](/packages/guzzlehttp-psr7)[php-http/multipart-stream-builder

A builder class that help you create a multipart stream

29490.9M224](/packages/php-http-multipart-stream-builder)[padraic/humbug_get_contents

Secure wrapper for accessing HTTPS resources with file\_get\_contents for PHP 5.3+

1255.3M5](/packages/padraic-humbug-get-contents)[ezimuel/guzzlestreams

Fork of guzzle/streams (abandoned) to be used with elasticsearch-php

176108.6M3](/packages/ezimuel-guzzlestreams)[ringcentral/psr7

PSR-7 message implementation

15322.2M62](/packages/ringcentral-psr7)[willwashburn/phpamo

A PHP library to create urls for Camo - the SSL image proxy

42159.6k1](/packages/willwashburn-phpamo)

PHPackages © 2026

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