VOOZH about

URL: https://deepwiki.com/rudderlabs/rudder-php-sdk/1.2-sdk-configuration-reference

⇱ SDK Configuration Reference | rudderlabs/rudder-php-sdk | DeepWiki


Loading...
Menu

SDK Configuration Reference

The RudderStack PHP SDK is initialized using the Rudder::init() static method. This method configures the global SDK behavior by passing a writeKey and an optional $options array. These configurations determine how data is batched, compressed, and transported to the RudderStack Data Plane.

Initialization Flow

When Rudder::init() is called, it performs URL normalization, handles SSL/TLS preferences, and instantiates a Client object which serves as the primary engine for event processing.

Initialization Logic Overview


Sources: lib/Rudder.php19-42 lib/Rudder.php212-232


Configuration Options Reference

The following table details all available keys for the $options array passed to Rudder::init(string $writeKey, array $options = []).

NameTypeDefaultDescription
consumerstringlib_curlThe transport strategy: lib_curl, fork_curl, socket, or file.
data_plane_urlstringhosted.rudderlabs.comThe destination URL for your RudderStack Data Plane.
debugboolfalseIf true, the SDK blocks for server responses and logs errors to error_log.
sslbooltrueWhether to use HTTPS. If false, http:// is used.
tlsboolfalseSpecifically for Socket consumer: uses tls:// instead of ssl://.
compress_requestbooltrueWhether to Gzip payloads before transmission.
max_queue_sizeint10000Maximum number of events allowed in the in-memory queue.
flush_atint100Number of events to buffer before triggering an automatic flush.
flush_intervalint10000Milliseconds to wait between batch transmissions if the queue isn't empty.
timeoutfloat0.5Connection timeout for Socket consumer (seconds).
curl_timeoutint0Total timeout for lib_curl requests (0 for infinite).
curl_connecttimeoutint300Connect timeout for lib_curl (milliseconds).
max_item_size_bytesint32000Max size for a single event (32KB).
max_queue_size_bytesint33554432Max total size of the queue (32MB).
error_handlercallablenullA function ($code, $msg) called when a request fails.
filenamestring/tmp/analytics.logPath for the File consumer log.
filepermissionsint0644Octal file permissions for the log file.

Sources: README.md35-53 lib/Consumer/QueueConsumer.php16-26 lib/Consumer/Socket.php23-30


Consumer Transport Selection

The consumer option determines which class is instantiated by the Client. Each consumer has unique performance characteristics.

1. LibCurl (Default)

Uses the PHP ext-curl extension for synchronous HTTP requests. It supports exponential backoff and Gzip compression.

2. ForkCurl

Executes a curl command via exec() to send data in the background (fire-and-forget).

3. Socket

Uses pfsockopen() for low-level TCP/IP communication.

4. File

Logs events to a local file for later processing by a cron job or sidecar.


Data Flow and Queue Limits

Consumers inheriting from QueueConsumer manage an internal $queue array. When enqueue() is called (via track, identify, etc.), the SDK checks several limits before adding the item.

Queue Validation and Flush Logic


Sources: lib/Consumer/QueueConsumer.php149-178 lib/Consumer/QueueConsumer.php106-131

Error Handling

If an error_handler is provided in the configuration, it is triggered by the handleError method in the base Consumer class.

Sources: lib/Consumer/Consumer.php92-103