OddSockets PHP SDK

Experience real-time communication with our comprehensive PHP SDK. Built for Laravel integration with ReactPHP and Ratchet WebSocket support.

ReactPHP/Ratchet Laravel Integration Real-time Messaging Presence Tracking

Connection Status

Disconnected
Server: https://connect.oddsockets.tyga.network

Basic Connection

Core

basic_connection.php

<?php
require_once 'vendor/autoload.php';

use OddSockets\OddSocketsClient;

// Create client instance
$client = new OddSocketsClient(
    'https://connect.oddsockets.tyga.network',
    'demo-api-key'
);

// Connect to server
$client->connect()->then(function() {
    echo "✅ Connected to OddSockets server\n";
    
    // Get connection stats
    $stats = $client->getConnectionStats();
    echo "📊 Connection established at: " . 
         $stats['connected_at'] . "\n";
         
    return $client->disconnect();
})->then(function() {
    echo "🔌 Disconnected successfully\n";
})->otherwise(function($error) {
    echo "❌ Error: " . $error . "\n";
});
Click "Run" to execute this demo...

Channel Messaging

Messaging

channel_messaging.php

<?php
use OddSockets\OddSocketsClient;

$client = new OddSocketsClient(
    'https://connect.oddsockets.tyga.network', 
    'demo-api-key'
);

$client->connect()->then(function() use ($client) {
    echo "🔗 Joining channel 'demo-chat'\n";
    return $client->joinChannel('demo-chat');
})->then(function() use ($client) {
    echo "📤 Sending message to channel\n";
    
    return $client->sendMessage('demo-chat', [
        'text' => 'Hello from PHP SDK!',
        'user' => 'php-demo-user',
        'timestamp' => date('c')
    ]);
})->then(function() use ($client) {
    echo "✅ Message sent successfully\n";
    
    // Get channel stats
    return $client->getChannelStats('demo-chat');
})->then(function($stats) use ($client) {
    echo "📊 Channel stats retrieved\n";
    return $client->leaveChannel('demo-chat');
})->then(function() {
    echo "🚪 Left channel successfully\n";
});
Click "Run" to execute this demo...

Laravel Integration

Laravel

laravel_example.php

<?php
// Laravel Controller Example
use OddSockets\Laravel\Facades\OddSockets;

class ChatController extends Controller
{
    public function sendMessage(Request $request)
    {
        // Validate input
        $request->validate([
            'channel' => 'required|string',
            'message' => 'required|string'
        ]);
        
        // Send message via OddSockets facade
        OddSockets::connect()->then(function() use ($request) {
            return OddSockets::joinChannel($request->channel);
        })->then(function() use ($request) {
            return OddSockets::sendMessage(
                $request->channel,
                [
                    'text' => $request->message,
                    'user' => auth()->user()->name,
                    'timestamp' => now()->toISOString()
                ]
            );
        })->then(function() {
            return response()->json([
                'success' => true,
                'message' => 'Message sent successfully'
            ]);
        });
    }
}
Click "Run" to execute this demo...

Presence Tracking

Presence

presence_tracking.php

<?php
use OddSockets\OddSocketsClient;

$client = new OddSocketsClient(
    'https://connect.oddsockets.tyga.network',
    'demo-api-key'
);

$client->connect()->then(function() use ($client) {
    return $client->joinChannel('lobby');
})->then(function() use ($client) {
    echo "👤 Setting presence data\n";
    
    return $client->setPresence('lobby', [
        'user_id' => 'php-user-123',
        'name' => 'PHP Demo User',
        'status' => 'online',
        'activity' => 'testing presence',
        'joined_at' => date('c')
    ]);
})->then(function() use ($client) {
    echo "✅ Presence data set\n";
    echo "📊 Getting presence information\n";
    
    return $client->getPresence('lobby');
})->then(function($presence) use ($client) {
    echo "👥 Active users in lobby: " . 
         count($presence['users'] ?? []) . "\n";
    
    return $client->leaveChannel('lobby');
})->then(function() {
    echo "🚪 Left lobby channel\n";
});
Click "Run" to execute this demo...

Activity Log

PHP SDK Demo Ready

Ready to run demonstrations

Modern PHP 8.0+

Built with modern PHP features including strict typing, attributes, and async support.

ReactPHP Integration

Powered by ReactPHP and Ratchet for high-performance WebSocket connections.

Laravel Ready

Complete Laravel integration with service providers, facades, and Artisan commands.

Production Ready

Comprehensive error handling, logging, and monitoring capabilities.