# \ConsumerStrategies_SocketConsumer

Consumes messages and writes them to host/endpoint using a persistent socket

## Summary

Methods
Properties
Constants
__construct()
getNumThreads()
persist()
No public properties found
No constants found
_encode()
_handleError()
_log()
_debug()
$_options
N/A
_getSocket()
_createSocket()
_destroySocket()
_write()
handleResponse()
$_defaults
$_host
$_endpoint
$_connect_timeout
$_protocol
$_socket
$_async
N/A

File
  ConsumerStrategies/SocketConsumer.php
Package
  Default
Class hierarchy
  \Base_MixpanelBase
  \ConsumerStrategies_AbstractConsumer
  \ConsumerStrategies_SocketConsumer

## Tags

None found

## Properties

### $_options

    $_options : array

An array of options to be used by the Mixpanel library.

#### Type

array

#

Inherited from
  \Base_MixpanelBase

## Tags

None found

### $_defaults

    $_defaults : array

Default options that can be overridden via the $options constructor arg

#### Type

array

#

Inherited from
  \Base_MixpanelBase

## Tags

None found

### $_host

    $_host : string

#### Type

string — the host to connect to (e.g. api.mixpanel.com)

#

## Tags

None found

### $_endpoint

    $_endpoint : string

#### Type

string — the host-relative endpoint to write to (e.g. /engage)

#

## Tags

None found

### $_connect_timeout

    $_connect_timeout : integer

#### Type

integer — connect_timeout the socket connection timeout in seconds

#

## Tags

None found

### $_protocol

    $_protocol : string

#### Type

string — the protocol to use for the socket connection

#

## Tags

None found

### $_socket

    $_socket : resource

#### Type

resource — holds the socket resource

#

## Tags

None found

### $_async

    $_async : boolean

#### Type

boolean — whether or not to wait for a response

#

## Tags

None found

## Methods

### __construct()

    __construct(array  $options = array())

Creates a new SocketConsumer and assigns properties from the $options array

#### Parameters

array | $options |

#

## Tags

None found

### getNumThreads()

    getNumThreads() : integer

Number of requests/batches that will be processed in parallel.

#### Returns

integer

#

Inherited from
  \ConsumerStrategies_AbstractConsumer

## Tags

None found

### persist()

    persist(array  $batch) : boolean

Write using a persistent socket connection.

#### Parameters

array | $batch | an array of messages to consume

#### Returns

boolean

#

## Tags

None found

### _encode()

    _encode(array  $params) : string

Encode an array to be persisted

#### Parameters

array | $params |

#### Returns

string

#

Inherited from
  \ConsumerStrategies_AbstractConsumer

## Tags

None found

### _handleError()

    _handleError(  $code,   $msg)

Handles errors that occur in a consumer

#### Parameters

| $code |
| $msg |

#

Inherited from
  \ConsumerStrategies_AbstractConsumer

## Tags

None found

### _log()

    _log(  $msg)

Log a message to PHP's error log

#### Parameters

| $msg |

#

Inherited from
  \Base_MixpanelBase

## Tags

None found

### _debug()

    _debug() : boolean

Returns true if in debug mode, false if in production mode

#### Returns

boolean

#

Inherited from
  \Base_MixpanelBase

## Tags

None found

### _getSocket()

    _getSocket() : boolean|resource

Return cached socket if open or create a new persistent socket

#### Returns

boolean|resource

#

## Tags

None found

### _createSocket()

    _createSocket(boolean  $retry = true) : boolean|resource

Attempt to open a new socket connection, cache it, and return the resource

#### Parameters

boolean | $retry |

#### Returns

boolean|resource

#

## Tags

None found

### _destroySocket()

    _destroySocket()

Attempt to close and dereference a socket resource

#

## Tags

None found

### _write()

    _write(  $socket,   $data, boolean  $retry = true) : boolean

Write $data through the given $socket

#### Parameters

| $socket |
| $data |
boolean | $retry |

#### Returns

boolean

#

## Tags

None found

### handleResponse()

    handleResponse(  $response) : array

Parse the response from a socket write (only used for debugging)

#### Parameters

| $response |

#### Returns

array

#

## Tags

None found

### SocketConsumer.php