Download the PHP package bk203/vici-php without Composer
On this page you can find all versions of the php package bk203/vici-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package vici-php
vici-php
A pure-PHP client implementation of strongSwan's VICI protocol. Use it from PHP to monitor, configure, and control the IKE daemon charon.
- Covers every command and event documented in the VICI README.
- Pluggable transport: Unix domain socket (default) or TCP, plus a generic
StreamTransportfor injection and testing. - Blocking
Sessionfor commands, plus anEventListenerfor long-running event subscriptions. - Streaming list commands (
list-sas,list-conns, ...) expose event streams as PHP generators. - Fully typed, PHPStan level 8 clean, zero runtime dependencies.
Requirements
- PHP 8.4+
- A reachable charon VICI socket. Defaults to the Unix socket
/var/run/charon.vici; TCP listeners are supported as well.
Install
Quick start
If you're happy with the defaults, new Session() alone connects to /var/run/charon.vici.
Connect over TCP
Inject a custom stream
Common workflows
Load a connection
Booleans are encoded as yes / no, integers and floats are stringified, and null values are skipped — matching the conventions used by the Python and Ruby reference clients.
Stream active SAs
Streaming commands return a Generator. If you break out early, the library automatically drains any remaining stream packets and unregisters the backing event before the next command can run, so the connection stays in sync.
Initiate / terminate
Commands whose response carries success = no raise CommandException carrying the command name and the decoded response.
Listen for events
A Session allows only one in-flight command at a time, so give a listener its own Session if you also want to issue commands concurrently from another thread/process. $listener->next($timeout) returns the next event (or null on timeout) if you'd rather poll than run a blocking loop.
Command reference
All commands return decoded arrays (or generators for streaming variants). Every helper ultimately delegates to Session::request() / Session::streamedRequest(), so you can always fall back to the generic API for new commands:
| Category | Methods |
|---|---|
| Control | version(), stats(), reloadSettings(), initiate(), terminate(), rekey(), redirect(), install(), uninstall() |
| Streaming | listSas(), listPolicies(), listConns(), listCerts(), listAuthorities() |
| Configuration | getConns(), getAuthorities(), loadConn(), unloadConn(), loadCert(), loadKey(), unloadKey(), getKeys(), loadToken(), loadShared(), unloadShared(), getShared(), flushCerts(), clearCreds(), loadAuthority(), unloadAuthority(), loadPool(), unloadPool(), getPools() |
| Diagnostics | getAlgorithms(), getCounters(), resetCounters() |
Event constants live on Bk203\Vici\Event (LOG, CONTROL_LOG, LIST_SA, LIST_POLICY, LIST_CONN, LIST_CERT, LIST_AUTHORITY, IKE_UPDOWN, IKE_REKEY, IKE_UPDATE, CHILD_UPDOWN, CHILD_REKEY, ALERT).
Error handling
All exceptions extend Bk203\Vici\Exception\ViciException:
| Exception | Thrown when |
|---|---|
ConnectionException |
Underlying socket cannot connect, closes mid-stream, or stream_select() fails |
TimeoutException |
Read/connect timeout elapses |
ProtocolException |
Framing or message-encoding violation on the wire |
CommandUnknownException |
Server replies with CMD_UNKNOWN |
CommandException |
Command completes with success = no; exposes ->command and ->response |
EventRegistrationException |
Server replies with EVENT_UNKNOWN to EVENT_REGISTER / EVENT_UNREGISTER |
Architecture
Bk203\Vici\Transport\TransportInterface— 32-bit length-prefixed framing (max 512 KiB), implemented byUnixSocketTransport,TcpSocketTransport, andStreamTransport.Bk203\Vici\Protocol\{Packet, PacketCodec, PacketType}— packet layer: the 8-bit type + optional 8-bit-length name tag + optional message payload.Bk203\Vici\Message\{MessageEncoder, MessageDecoder, ElementType}— the hierarchical message tree: sections, key/value pairs (16-bit value length), and lists.Bk203\Vici\Session— the high-level API: command dispatch, event interleaving, reference-counted event (de-)registration, and typed wrappers for every VICI command.Bk203\Vici\EventListener— convenience layer overSessionfor long-running event subscriptions.
Development
Integration tests use an in-process MockViciServer backed by a socket pair, so no real charon daemon or container is required.
Docker development environment
A bare Ubuntu 24.04 container runs strongSwan charon plus PHP 8.4 so you can
exercise the library against a real VICI socket without installing anything on
the host. charon is started by the entrypoint and listens on
/var/run/charon.vici for the lifetime of the container.
With the container shell you can hit the live daemon directly:
The compose file bind-mounts the repository at /app, so host-side edits are
picked up immediately. NET_ADMIN is granted to leave the door open for
initiate() / kernel IPsec experiments, but it is not required for VICI
commands like version(), stats(), load-conn, or list-sas.
License
MIT. See LICENSE.
Acknowledgements
Modelled after the reference Python and Go VICI clients from the strongSwan project.