Skip to content

Instantly share code, notes, and snippets.

@gbowne1
Created February 14, 2026 03:46
Show Gist options
  • Select an option

  • Save gbowne1/a1119991ae86937dc4c45be5701f2c04 to your computer and use it in GitHub Desktop.

Select an option

Save gbowne1/a1119991ae86937dc4c45be5701f2c04 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
use SoureCode\ObsWebsocket\Client;
use SoureCode\ObsWebsocket\Request\Record\ToggleRecordRequest;
// 1. Initialize the client
// Replace 'your_password' with the password from OBS WebSocket settings
$client = new Client('ws://127.0.0.1:4455', 'your_password');
try {
// 2. Connect to OBS
// The library handles the 'Hello'/'Identify' handshake automatically
$client->connect();
echo "Successfully connected to OBS!\n";
// 3. Send a Request (Example: Toggle Recording)
$response = $client->send(new ToggleRecordRequest());
if ($response->isSuccess()) {
echo "Recording toggled successfully.\n";
} else {
echo "Failed to toggle recording: " . $response->getError() . "\n";
}
// 4. Close connection when done
$client->disconnect();
} catch (\Exception $e) {
echo "Connection error: " . $e->getMessage() . "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment