PHPackages                             eventflit/eventflit-http-php - 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. [API Development](/categories/api)
4. /
5. eventflit/eventflit-http-php

ActiveLibrary[API Development](/categories/api)

eventflit/eventflit-http-php
============================

Library for interacting with the Eventflit REST API

00PHP

Since Apr 24Pushed 8y ago1 watchersCompare

[ Source](https://github.com/eventflit/eventflit-http-php)[ Packagist](https://packagist.org/packages/eventflit/eventflit-http-php)[ RSS](/packages/eventflit-eventflit-http-php/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Eventflit PHP Library
=====================

[](#eventflit-php-library)

PHP library for interacting with the Eventflit HTTP API.

Register at  and use the application credentials within your app as shown below.

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

[](#installation)

You can get the Eventflit PHP library via a composer package called `eventflit-http-php`. See

```
$ composer require eventflit/eventflit-http-php
```

Or add to `composer.json`:

```
"require": {
    "eventflit/eventflit-http-php": "^0.1"
}
```

and then run `composer update`.

Or you can clone or download the library files.

**We recommend you [use composer](http://getcomposer.org/).**

This library depends on PHP modules for cURL and JSON. See [cURL module installation instructions](http://php.net/manual/en/curl.installation.php) and [JSON module installation instructions](http://php.net/manual/en/json.installation.php).

Eventflit constructor
---------------------

[](#eventflit-constructor)

Use the credentials from your Eventflit application to create a new `Eventflit\Eventflit` instance.

```
$app_id = 'YOUR_APP_ID';
$app_key = 'YOUR_APP_KEY';
$app_secret = 'YOUR_APP_SECRET';
$app_cluster = 'YOUR_APP_CLUSTER';

$eventflit = new Eventflit\Eventflit( $app_key, $app_secret, $app_id, array('cluster' => $app_cluster) );
```

The fourth parameter is an `$options` array. The additional options are:

- `scheme` - e.g. http or https
- `host` - the host e.g. service.eventflit.com. No trailing forward slash.
- `port` - the http port
- `timeout` - the HTTP timeout
- `encrypted` - quick option to use scheme of https and port 443.
- `cluster` - specify the cluster where the application is running from.
- `curl_options` - array with custom curl commands

For example, by default calls will be made over a non-encrypted connection. To change this to make calls over HTTPS use:

```
$eventflit = new Eventflit\Eventflit( $app_key, $app_secret, $app_id, array( 'cluster' => $app_cluster, 'encrypted' => true ) );
```

For example, if you want to set custom curl options, use this:

```
$eventflit = new Eventflit\Eventflit( $app_key, $app_secret, $app_id, array( 'cluster' => $app_cluster, 'encrypted' => true, 'curl_options' => array( CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4 ) ) );
```

*Note: The `host` option overrides the `cluster` option!*

Publishing/Triggering events
----------------------------

[](#publishingtriggering-events)

To trigger an event on one or more channels use the `trigger` function.

### A single channel

[](#a-single-channel)

```
$eventflit->trigger( 'my-channel', 'my_event', 'hello world' );
```

### Multiple channels

[](#multiple-channels)

```
$eventflit->trigger( [ 'channel-1', 'channel-2' ], 'my_event', 'hello world' );
```

### Batches

[](#batches)

It's also possible to send multiple events with a single API call (max 10 events per call on multi-tenant clusters):

```
$batch = array();
$batch[] = array('channel' => 'my-channel', 'name' => 'my_event', 'data' => array('hello' => 'world'));
$batch[] = array('channel' => 'my-channel', 'name' => 'my_event', 'data' => array('myname' => 'bob'));
$eventflit->triggerBatch($batch);
```

### Arrays

[](#arrays)

Objects are automatically converted to JSON format:

```
$array['name'] = 'joe';
$array['message_count'] = 23;

$eventflit->trigger('my_channel', 'my_event', $array);
```

The output of this will be:

```
"{'name': 'joe', 'message_count': 23}"
```

### Socket id

[](#socket-id)

In order to avoid duplicates you can optionally specify the sender's socket id while triggering an event ([https://eventflit.com/docs/duplicates](http://eventflitapp.com/docs/duplicates)):

```
$eventflit->trigger('my-channel','event','data','socket_id');
```

### JSON format

[](#json-format)

If your data is already encoded in JSON format, you can avoid a second encoding step by setting the sixth argument true, like so:

```
$eventflit->trigger('my-channel', 'event', 'data', null, false, true)
```

Authenticating Private channels
-------------------------------

[](#authenticating-private-channels)

To authorise your users to access private channels on Eventflit, you can use the socket\_auth function:

```
$eventflit->socket_auth('private-my-channel','socket_id');
```

Authenticating Presence channels
--------------------------------

[](#authenticating-presence-channels)

Using presence channels is similar to private channels, but you can specify extra data to identify that particular user:

```
$eventflit->presence_auth('presence-my-channel','socket_id', 'user_id', 'user_info');
```

### Presence example

[](#presence-example)

First set this variable in your JS app:

```
Eventflit.channel_auth_endpoint = '/presence_auth.php';
```

Next, create the following in presence\_auth.php:

```
