VOOZH about

URL: https://deepwiki.com/stefanak-michal/php-bolt-driver/9.1-setup-and-dependencies

⇱ Setup and Dependencies | stefanak-michal/php-bolt-driver | DeepWiki


Loading...
Last indexed: 14 February 2026 (a283bd)
Menu

Setup and Dependencies

This document details the system requirements, dependencies, and installation setup for the php-bolt-driver library. It covers PHP version requirements, required and optional extensions, the PSR-16 cache interface requirement, and development dependencies for contributors. For information about running tests after setup, see Running Tests. For connection-specific configuration after installation, see Connection Implementations and SSL/TLS Configuration.

Purpose and Scope

This page documents the dependency requirements and installation process for the php-bolt-driver library. It explains which dependencies are mandatory, which are optional based on feature usage, and the roles each dependency plays in the library's operation.


Core Dependencies

PHP Version Requirement

The library requires PHP 8.1 or higher as specified in composer.json11 The codebase leverages modern PHP features including typed properties, constructor property promotion, and union types that were introduced in PHP 8.x versions. Testing is performed across PHP versions 8.2 through 8.5 as documented in the CI/CD workflows.

Required Composer Dependencies

PackageVersionPurpose
psr/simple-cache^3.0PSR-16 cache interface for persistent connection metadata

The psr/simple-cache package provides the CacheInterface that is required for persistent connection management via the PStreamSocket class. See Persistent Connections with PStreamSocket for details on cache usage.

Required PHP Extensions

ExtensionPurposeUsed By
ext-mbstringMultibyte string operations for UTF-8 handling in PackStream serializationPacker, Unpacker classes
ext-curlHTTP requests for anonymous analytics trackingAnalytics class

The ext-mbstring extension is critical for correct handling of UTF-8 encoded strings during PackStream serialization and deserialization. The ext-curl extension enables the optional analytics feature that tracks library usage statistics anonymously.

Sources: composer.json10-14


Optional Dependencies

Socket Extension (ext-sockets)

The ext-sockets extension is required only when using the Socket connection class, which provides low-level socket operations using PHP's socket functions.


The Socket class directly uses socket functions such as socket_create(), socket_connect(), socket_set_option(), socket_read(), and socket_write() which are only available when ext-sockets is installed. If you choose to use StreamSocket or PStreamSocket instead, this extension is not required.

When to use Socket:

  • When you need direct control over socket-level operations
  • When you prefer the socket API over stream functions
  • When not using SSL/TLS connections

Sources: composer.json50 src/connection/Socket.php

OpenSSL Extension (ext-openssl)

The ext-openssl extension is required when using the StreamSocket class with SSL/TLS encryption enabled. This is essential for secure connections to cloud-hosted Neo4j instances or any deployment requiring encrypted transport.


The StreamSocket::setSslContextOptions() method accepts an array of SSL context options that are passed directly to PHP's stream_context_create() function. Without ext-openssl, SSL/TLS connections will fail with a runtime error.

When to use OpenSSL:

  • Connecting to Neo4j Aura or other cloud providers
  • Production deployments requiring encryption in transit
  • Compliance requirements for encrypted database connections

For detailed SSL/TLS configuration, see SSL/TLS Configuration and Security.

Sources: composer.json51 src/connection/StreamSocket.php


PSR-16 Cache Requirements

The library requires a PSR-16 compatible cache implementation when using persistent connections via PStreamSocket. The cache interface is declared as a dependency in composer.json14 but no concrete implementation is included in the library.


Included FileCache Implementation

The library includes a basic FileCache class in src/FileCache.php that stores cache entries as JSON files in a specified directory. This implementation is suitable for development and single-server deployments but has limitations:

  • File-based storage: Cache entries stored as individual JSON files
  • No distributed caching: Not suitable for multi-server deployments
  • Basic TTL support: Entries expire based on ttl parameter
  • Directory permissions: Requires write access to cache directory

Using Alternative Cache Implementations

For production deployments, especially with multiple application servers, you should provide a distributed cache implementation:

Cache TypeUse CaseExample Packages
RedisMulti-server deployments, high performancesymfony/cache, cache/redis-adapter
MemcachedMulti-server deployments, distributed cachingsymfony/cache, cache/memcached-adapter
APCuSingle-server deployments, in-memory cachingsymfony/cache, cache/apcu-adapter
FilesystemDevelopment, single-server simple deploymentsBuilt-in FileCache

Cache Data Stored

The cache is used for:

  1. Protocol version metadata (15-minute TTL): When PStreamSocket successfully connects and negotiates a protocol version, it caches the version number to avoid redundant handshakes on subsequent connections
  2. Server information: Cached during the connection lifecycle
  3. Analytics data: Anonymous usage statistics for opt-in analytics tracking

For details on cache usage in persistent connections, see Persistent Connections with PStreamSocket.

Sources: composer.json14 src/FileCache.php src/connection/PStreamSocket.php src/Analytics.php


Development Dependencies

Contributors and developers running tests require additional dependencies specified in the require-dev section:

PackageVersionPurpose
phpunit/phpunit^9Testing framework for unit and integration tests

PHPUnit 9 is used for the comprehensive test suite covering:

  • Protocol message handling (V1 through V6)
  • PackStream serialization/deserialization
  • Connection management and timeouts
  • Graph, temporal, and spatial structures
  • Performance testing with 50,000 record sets

The test suite is organized into multiple configurations in phpunit.xml:

  • NoDatabase suite: Unit tests for Packer, Unpacker, and connection classes
  • Neo4j suite: Integration tests across Neo4j versions 4.4 through 2025
  • Database-specific suites: Memgraph and NornicDB compatibility tests

For detailed testing instructions, see Running Tests. For CI/CD pipeline details, see CI/CD Pipeline and Cross-Version Testing.

Sources: composer.json16-18 phpunit.xml


Installation Steps

Basic Installation via Composer


This installs the library with all required dependencies. The autoloader configuration uses PSR-4 mapping from the Bolt\ namespace to the src/ directory as defined in composer.json37-40

Installation with Optional Extensions

If using the Socket connection class:


If using SSL/TLS with StreamSocket:


Installation for Development

For contributors who need to run tests:


The composer test script is configured in composer.json53-58 to run PHPUnit with appropriate environment settings.

Verifying Installation

After installation, verify that required extensions are enabled:


You can also check PHP version compatibility:


Sources: composer.json1-60


Dependency Resolution Diagram


This diagram shows the complete dependency tree from application code down to specific extensions and interfaces. Solid lines indicate direct usage, dashed lines indicate conditional requirements or interface implementations.

Sources: composer.json10-52 src/Bolt.php src/protocol/AProtocol.php src/packstream/Packer.php src/packstream/Unpacker.php src/connection/Socket.php src/connection/StreamSocket.php src/connection/PStreamSocket.php src/Analytics.php src/FileCache.php


Summary Table

RequirementTypeUsed ByNotes
PHP 8.1+MandatoryAll codeTested on 8.2-8.5
ext-mbstringMandatoryPacker, UnpackerUTF-8 string handling
ext-curlMandatoryAnalyticsHTTP requests for tracking
psr/simple-cache ^3.0MandatoryPStreamSocket, AnalyticsInterface only, implementation required
ext-socketsOptionalSocketOnly if using Socket class
ext-opensslOptionalStreamSocketOnly if using SSL/TLS
phpunit/phpunit ^9Dev onlyTest suiteFor contributors

Sources: composer.json10-18