PHPackages                             socketbee/socketbee - 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. socketbee/socketbee

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

socketbee/socketbee
===================

SocketBee PHP client. A simple and efficient PHP SDK for sending real-time events using the SocketBee API.

10PHP

Since Jun 2Pushed 1y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

SocketBee PHP library
---------------------

[](#socketbee-php-library)

[SocketBee](https://socketbee.com) provides an easy-to-use API for sending real-time events to your applications. This PHP SDK enables you to interact with the SocketBee service effortlessly.

Installation
------------

[](#installation)

To use the SocketBee SDK in your PHP project, you can install it via Composer. Run the following command in your project directory:

```
composer require socketbee/socketbee
```

Usage
-----

[](#usage)

Here's a step-by-step guide on how to use the SocketBee PHP SDK:

### Step 1: Load the Composer Autoloader

[](#step-1-load-the-composer-autoloader)

Ensure the Composer autoloader is included in your script:

```
require 'vendor/autoload.php';
```

### Step 2: Initialize the SocketBee Client

[](#step-2-initialize-the-socketbee-client)

Create an instance of the `SocketBee` class with your application ID, secret, and key. These credentials can be obtained from your [SocketBee Dashboard](https://platform.socketbee.com).

```
$app_id = getenv('APP_ID');
$secret = getenv('APP_SECRET');
$key = getenv('APP_KEY');

$eventSender = new \SocketBee\SocketBee($app_id, $secret, $key);
```

### Step 3: Send an Event

[](#step-3-send-an-event)

Use the `sendEvent` method to send an event to a specific channel. The method requires the channel name, event name, and event data.

```
$s = $eventSender->sendEvent('cool_channel', 'new-message', 'very cool stuff!');
```

### Step 4: Handle the Response

[](#step-4-handle-the-response)

The `sendEvent` method returns an array containing the status and the body of the response. You can use this information to handle the success or failure of the event.

```
var_dump($s);
```

Example
-------

[](#example)

Below is a complete example demonstrating how to use the SocketBee SDK in a PHP script:

```
