PHPackages                             oddsmatrix/sepc-connector - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. oddsmatrix/sepc-connector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oddsmatrix/sepc-connector
=========================

SEPC Connector implementation for PHP

11.2k2[2 issues](https://github.com/bogdan-beldea-em/sepc-connector-php/issues)[1 PRs](https://github.com/bogdan-beldea-em/sepc-connector-php/pulls)PHP

Since Mar 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/bogdan-beldea-em/sepc-connector-php)[ Packagist](https://packagist.org/packages/oddsmatrix/sepc-connector)[ RSS](/packages/oddsmatrix-sepc-connector/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Readme
======

[](#readme)

The Sports Engine Publication Component (SEPC) is the component to which clients connect in order to get the Sports Engine data.

We provide a PHP-based connector which knows how to connect to and communicate with the SEPC.

Current version: `0.1.29-dev`

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

[](#installation)

The connector can be found in the public Packagist repository under the `oddsmatrix/sepc-connector` name. To install, just run `composer require oddsmatrix/sepc-connector` in the root of your Composer based project.

###### Note

[](#note)

Before the actual release, in order to be able to run the `composer require` command the following steps must be followed:

- Clone the `sepc-connector-php` repository
- Add the `repositories` entry in the `composer.josn` file at the root of your project if it's not already there. For the SEPC library entry:
    - Set the repository type to `vcs`
    - Set the url of the repository as a path to your local `sepc-connector-php` clone
- Add the `minimum-stability` entry in the `composer.json` file and set it to `dev`

```
{
    "type": "project",
    "license": "proprietary",
    "repositories": [{
        "type": "vcs",
        "url": "//sepc-connector-php"
    }],
    "minimum-stability": "dev",
    "require": {
        "php": "^7.2.5",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "oddsmatrix/sepc-connector": "dev-master",
...

```

Run `composer require oddsmatrix/sepc-connector`.

The `"oddsmatrix/sepc-connector": "dev-master",` line should now show up in your `composer.json`.

Usage
-----

[](#usage)

The SEPC Connector can be used in 3 modes:

- PUSH - Direct Socket connection to the Sports Engine. This configuration provides the fastest updates as the SE constantly pushes updates.
- PULL - Retrieves data using the HTTP protocol. Friendlier with spotty internet connection, update rate is 1/30s
- Preserved-state PULL - Same as PULL, but allows for saving state (authentication/dump completion status) between requests. This is useful when you want to poll the SE from a `supervisor` or a `serverless function`.

### PUSH

[](#push)

#### 1. Create the `SEPCCredentials`

[](#1-create-the-sepccredentials)

Refer to the common section.

#### 2. Instantiate the `SEPCPushConnector` class

[](#2-instantiate-the-sepcpushconnector-class)

```
use OM\OddsMatrix\SEPC\Connector\SEPCPushConnector;

$connector = new SEPCPushConnector(
            $credentials,
            $logger
        );

```

#### 3. Connect

[](#3-connect)

For socket connections use port 7000.

```
$connector->connect("sept.oddsmatrix.com", 7000);

```

#### 4. Poll for updates

[](#4-poll-for-updates)

```
/** @var SDQLResponse|null $response */
$response = $connector->getNextData();

```

### Preserved state PUSH

[](#preserved-state-push)

#### 1. Create the `SEPCCredentials`

[](#1-create-the-sepccredentials-1)

Refer to the common section.

#### 2. Retrieve the persisted state file

[](#2-retrieve-the-persisted-state-file)

We will use the same `SDQLSerializer` for serializing and deserializing the persisted state.

```
$stateFilePath = ...;
$serializer = SDQLSerializerProvider::getSerializer();
$state = null;

try {
    $stateFileContent = file_get_contents($stateFilePath);
    if (false !== $stateFileContent) {
        $state = $serializer->deserialize($stateFileContent, PersistableConnectionState::class, 'xml');
    }
} catch (\Exception $e) {
    ...
}

```

In case there is no state to be read, we will create a new empty state.

```
if (is_null($state)) {
    $state = new PersistableConnectionState();
}

```

#### 3. Create the connector

[](#3-create-the-connector)

For socket connections use port 7000.

```
$connector = new SEPCPushConnector(
            $credentials,
            $this->_logger,
            $state
        );

```

#### 4. Connect

[](#4-connect)

```
$connector->autoconnect("sept.oddsmatrix.com", 7000);

```

#### 5. Poll the connector for data

[](#5-poll-the-connector-for-data)

```
/** @var SDQLResponse|null $response */
$response = $connector->getNextData();

```

#### 6. Persist the updated state after every poll

[](#6-persist-the-updated-state-after-every-poll)

```
file_put_contents($stateFilePath, $serializer->serialize($connector->getConnectionState(), 'xml'));

```

#### (Optional) Keeping the process alive with `supervisor`

[](#optional-keeping-the-process-alive-with-supervisor)

It is important to set the supervisor directory argument first. (which sets the CWD) Here is an example supervisor config for a Symfony application. Supervisor configuration files should reside in `/etc/supervisor.d/` and should have a `.ini` extension. Note that `stderr` and `stdout` forwarding make sense only if the logging interface prints to console.

```
[program:push-persisted-state]
directory=$HOME/sepc-connector-test
command=$HOME/sepc-connector-test/bin/console sepc:push -vv --state-file-path=$HOME/sepc-state.xml
autostart=true
startsecs=60
startretries=5
autorestart=true
stopsignal=KILL
stdout_logfile=/var/log/sepc/push_stdout.log
stderr_logfile=/var/log/sepc/push_stderr.log
stdout_logfile_maxbytes=1GB
stderr_logfile_maxbytes=1GB

```

### PULL

[](#pull)

#### 1. Create `SEPCCredentials`

[](#1-create-sepccredentials)

Refer to the common section.

#### 2. Instantiate the `SEPCPullConnector` class

[](#2-instantiate-the-sepcpullconnector-class)

```
$connector = new SEPCPullConnector(
            $credentials,
            $this->_logger
        );

```

#### 3. Connect

[](#3-connect-1)

For HTTP connections use port 8081.

```
$connector->connect("http://sept.oddsmatrix.com", 8081);

```

#### 4. Poll for updates

[](#4-poll-for-updates-1)

```
/** @var SDQLResponse|null $response */
$response = $connector->getNextData();

```

### Preserved-state PULL

[](#preserved-state-pull)

#### 1. Create `SEPCCredentials`

[](#1-create-sepccredentials-1)

Refer to the common section.

#### 2. Implement a persistable version of the `SEPCConnectionStateInterface`

[](#2-implement-a-persistable-version-of-the-sepcconnectionstateinterface)

Here is an example of a persistable version of the connection state interface that can be serialized and deserialized using JMS Serializer.

In this example we will use this persistable connection state in order to save the state on the filesystem between subsequent invocations.

Note that we've also added a request counter to this persistable connection state. It is not necessary, just for logging purposes.

```
