Download the PHP package oshitsd/php-socket without Composer
On this page you can find all versions of the php package oshitsd/php-socket. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oshitsd/php-socket
More information about oshitsd/php-socket
Files in oshitsd/php-socket
Package php-socket
Short Description 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.
License MIT
Homepage https://github.com/oshit-sd/php-socket
Informations about the package php-socket
๐ก PhpSocket
PhpSocket is a Laravel wrapper for handling Socket.IO WebSocket communication using a simple, expressive API. Built on top of the textalk/websocket client, it allows your Laravel app to communicate easily with a Socket.IO server.
๐ 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
- PHP 7.4 or higher
- Laravel 8, 9, 10, 11, 12 or upper
- WebSocket server with Socket.IO (EIO=4) support
๐ฆ Installation
Install via Composer:
Publish the config file:
This will create a config/phpsocket.php file where you can configure the WebSocket host and port.
โ๏ธ Configuration
In your .env file, add:
Or modify the config/phpsocket.php file directly.
๐งช Basic Usage
๐ Connect to Socket
Without Authentication
With Authentication
๐ค Send a Message
๐ฉ Receive Message Response
๐ Close the Connection
๐ฃ๏ธ Example Route Usage
You can quickly test sending a message using a simple route in your Laravel application.
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
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
๐งผ Example Output
๐งช Testing
You can run the package tests with:
Tests are located in the tests/ directory.
๐ License
This package is open-source software licensed under the MIT license.
๐จโ๐ป Credits
Developed by OSHIT SD
WebSocket client powered by textalk/websocket