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

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

oshitsd/php-socket
==================

A PHP package to interact with WebSocket servers. It provides methods to connect, send, receive, and close WebSocket connections, with Laravel integration for seamless usage.

v1.0.4(11mo ago)325MITPHPPHP ^7.4 || ^8.0

Since Apr 24Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/oshit-sd/php-socket)[ Packagist](https://packagist.org/packages/oshitsd/php-socket)[ Docs](https://github.com/oshit-sd/php-socket)[ RSS](/packages/oshitsd-php-socket/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

📡 PhpSocket
===========

[](#-phpsocket)

**PhpSocket** is a Laravel wrapper for handling Socket.IO WebSocket communication using a simple, expressive API. Built on top of the [`textalk/websocket`](https://github.com/Textalk/websocket) client, it allows your Laravel app to communicate easily with a Socket.IO server.

---

🚀 Features
----------

[](#-features)

- Connect to a Socket.IO WebSocket server
- Send and receive messages
- Built-in support for custom payloads and events
- Laravel Facade for simple usage
- Configurable host and port

---

🧰 Requirements
--------------

[](#-requirements)

- PHP 7.4 or higher
- Laravel 8, 9, 10, 11, 12 or upper
- WebSocket server with Socket.IO (EIO=4) support

---

📦 Installation
--------------

[](#-installation)

Install via Composer:

```
composer require oshitsd/php-socket
```

Publish the config file:

```
php artisan vendor:publish --tag=phpsocket-config
```

This will create a `config/phpsocket.php` file where you can configure the WebSocket host and port.

---

⚙️ Configuration
----------------

[](#️-configuration)

In your `.env` file, add:

```
PHP_SOCKET_ENV=production
PHP_SOCKET_HOST=socket.techcanvas.info
PHP_SOCKET_API_KEY=demo-tech-canvas-api-key
```

Or modify the `config/phpsocket.php` file directly.

---

🧪 Basic Usage
=============

[](#-basic-usage)

🔌 Connect to Socket
-------------------

[](#-connect-to-socket)

### Without Authentication

[](#without-authentication)

```
use Oshitsd\PhpSocket\Facades\PhpSocket;

PhpSocket::connect();
```

### With Authentication

[](#with-authentication)

```
use Oshitsd\PhpSocket\Facades\PhpSocket;

$connect = PhpSocket::connect([
    "room" => "DEMO_CHAT_ROOM" // Required: Name of the chat room to join
    "role" => "user", // Optional: User role, defaults to 'user'. Options: 'user' or 'agent'
    "userId" => 8001, // Optional: Unique user identifier
    "userName" => "OSHIT SUTRA DAR", // Optional: Display name of the user
]);
```

---

📤 Send a Message
----------------

[](#-send-a-message)

```
$response = PhpSocket::send([
    "event" => "demo_chat", // Required: Name of the event to broadcast
    "to" => "all", // Target recipient(s). Options: 'all' (broadcast to everyone) or a specific user ID to send a private message.
    "message" => [
        "time" => date('Y-m-d H:i:s'),
        "text" => "Laravel says hi 👋",
        "user" => [
            "id" => 8001,
            "name" => "OSHIT SUTRA DAR"
        ]
    ]
]);
```

---

📩 Receive Message Response
--------------------------

[](#-receive-message-response)

```
$response = PhpSocket::receiveAck();
```

---

🔒 Close the Connection
----------------------

[](#-close-the-connection)

```
$close = PhpSocket::close();
```

---

🛣️ Example Route Usage
----------------------

[](#️-example-route-usage)

You can quickly test sending a message using a simple route in your Laravel application.

```
use Illuminate\Support\Facades\Route;
use Oshitsd\PhpSocket\Facades\PhpSocket;

Route::get('send-notification', function () {

    $connect = PhpSocket::connect([
        "room" => "DEMO_CHAT_ROOM",
        "userId" => 8001,
        "userName" => "OSHIT SUTRA DAR",
    ]);

    $response = PhpSocket::send([
        "event" => "demo_chat",
        "to" => "all",
        "message" => [
            "time" => date('Y-m-d H:i:s'),
            "text" => "Laravel says hi 👋",
            "user" => [
                "id" => 8001,
                "name" => "OSHIT SUTRA DAR"
            ]
        ]
    ]);

    $close = PhpSocket::close();

    // Return the connection and message response
    return response()->json([
        'connect' => $connect,
        'response' => $response,
        'close' => $close
    ]);
});
```

When you visit `http://your-app-url/send-notification`, this route will:

- Connect to the WebSocket server
- Send a message to all connected clients
- Return the connection and response details as a JSON response

### 🔍 Live Demo

[](#-live-demo)

Once you hit the route `http://your-app-url/send-notification`, the message will be broadcasted to all connected clients.

You can **view the real-time message output** here: 👉 [Chat App Demo](https://oshit-sd-chat-app.vercel.app/)

---

🧼 Example Output
----------------

[](#-example-output)

```
👋 Connected to socket server successfully.
📤 Message sent.
📨 Received: {message response}
🔒 Connection closed.
```

---

🧪 Testing
---------

[](#-testing)

You can run the package tests with:

```
./vendor/bin/phpunit
```

Tests are located in the `tests/` directory.

---

📄 License
---------

[](#-license)

This package is open-source software licensed under the [MIT license](LICENSE).

---

👨‍💻 Credits
-----------

[](#‍-credits)

Developed by [OSHIT SD](https://github.com/oshit-sd)
WebSocket client powered by [textalk/websocket](https://github.com/Textalk/websocket)

[![Packagist Version](https://camo.githubusercontent.com/b5695b42078ab4809146e1f4a6b424711511277b2a67e640455880ec3f8bf808/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f7368697473642f7068702d736f636b6574)](https://camo.githubusercontent.com/b5695b42078ab4809146e1f4a6b424711511277b2a67e640455880ec3f8bf808/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f7368697473642f7068702d736f636b6574)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance52

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 73.3% 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 ~13 days

Total

5

Last Release

337d ago

PHP version history (3 changes)v1.0.0PHP ^8.0

v1.0.1PHP ^7.0 || ^8.0

v1.0.2PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e2feae834cdfc0fb5939637804604a744a9ab8885f9b022c163d917c9b2aa9d?d=identicon)[oshit-sd](/maintainers/oshit-sd)

---

Top Contributors

[![oshit-sd](https://avatars.githubusercontent.com/u/41891355?v=4)](https://github.com/oshit-sd "oshit-sd (11 commits)")[![oshit-rul](https://avatars.githubusercontent.com/u/148440699?v=4)](https://github.com/oshit-rul "oshit-rul (4 commits)")

---

Tags

phplaravelwebsocketSocketSocket.iophp-websocket

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[denis660/laravel-centrifugo

Centrifugo broadcaster for laravel

113164.7k](/packages/denis660-laravel-centrifugo)[basement-chat/basement-chat

Add a real-time chat widget to your Laravel application.

4983.9k](/packages/basement-chat-basement-chat)[sockeon/sockeon

Framework-agnostic PHP WebSocket and HTTP server library with attribute-based routing and support for namespaces and rooms.

291.3k2](/packages/sockeon-sockeon)[warriorxk/phpwebsockets

A websocket library with support for IPC using socket pairs

1225.3k](/packages/warriorxk-phpwebsockets)[soleon/sc-php

SocketCluster - PHP library for interacting with the SocketCluster.io

1531.8k](/packages/soleon-sc-php)

PHPackages © 2026

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