This project demonstrates how to use connect to a WebSocket server from PHP active as a client.
- Connects to a PieSocket WebSocket channel.
- Sends a message to the server.
- Receives and displays the server's response.
Before you start, ensure you have the following:
- PHP 7.4+ installed.
- Composer installed for dependency management.
- A valid PieSocket account to get your API key, cluster ID, and channel ID.
- Clone the repository:
git clone https://github.com/piehostHQ/php-ws-client.git cd piesocket-php-client-example
Install dependencies using Composer:
composer installUsage Replace the placeholders in the script (index.php) with your PieSocket credentials:
$channelId = "your-channel-id";
$clusterId = "your-cluster-id";
$apiKey = "your-api-key";Run the script:
php webSocketClient.phpObserve the server's response in the console.
Example Output
Response from server: Hello from PieSocket!