libtmux / libtmux-php
tmux client library for PHP 8.4+
Requires
- php: ^8.4
- php-64bit: *
Requires (Dev)
- php-cs-fixer/shim: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- revolt/event-loop: ^1
- symfony/process: ^7.4 || ^8.0
Suggests
- revolt/event-loop: Install ^1 to run nonblocking tmux operations on a Revolt event loop.
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-05 12:17:13 UTC
README
libtmux for PHP
Select a pane from a tmux snapshot and send it commands over its verified socket. Requires 64-bit Linux, PHP 8.4–8.x and tmux 3.3a or later.
Start a private server
Install the 0.0.1 alpha from Packagist in your Composer application.
$ composer require 'libtmux/libtmux-php:^0.0.1@alpha'
Run this PHP file from the application root. The new session returns the first pane ID. Executable example
<?php declare(strict_types=1); use LibTmux\Server; use LibTmux\Transport\Program; require __DIR__ . '/vendor/autoload.php'; $server = Server::createPrivate(); try { $session = $server->newSession('work', Program::argv('cat', '-u')); echo $session->pane->id->value, PHP_EOL; } finally { $server->close(); }
%0
Select the active pane in a session
A snapshot freezes pane values and relationships. You can filter its rows repeatedly after the server closes. Executable example
<?php declare(strict_types=1); use LibTmux\Model\Pane; use LibTmux\Model\Session; use LibTmux\Model\WindowLink; use LibTmux\Server; use LibTmux\Transport\Program; require __DIR__ . '/vendor/autoload.php'; $server = Server::createPrivate(); try { $program = Program::argv('cat', '-u'); $server->newSession('other', $program); $server->newSession('work', $program); $snapshot = $server->snapshot(); $session = $snapshot->sessions() ->filter(static fn(Session $session): bool => $session->name === 'work') ->one(); $link = $session->windowLinks() ->filter(static fn(WindowLink $link): bool => $link->active) ->one(); $pane = $link->window()->panes() ->filter(static fn(Pane $pane): bool => $pane->active) ->one(); echo $pane->id->value, " is active in $session->name\n"; } finally { $server->close(); }
%1 is active in work
Use oneOrNull() when a pane
may be absent. If several panes match,
inspect the candidates or
refine the filter.
Split and capture a pane
Split an observed pane and wait for the program in the new pane to reply. Executable example
<?php declare(strict_types=1); use LibTmux\Server; use LibTmux\Transport\Deadline; use LibTmux\Transport\Key; use LibTmux\Transport\Program; require __DIR__ . '/vendor/autoload.php'; $server = Server::createPrivate(); try { $server->newSession('work', Program::argv('cat', '-u')); $observed = $server->snapshot()->panes()->one(); $code = <<<'PHP' $line = fgets(STDIN); echo "reply=", $line; fgets(STDIN); PHP; $worker = Program::argv(PHP_BINARY, '-r', $code); $right = $server->pane($observed->ref)->splitHorizontal($worker); $right->sendText('ready'); $right->sendKeys(Key::Enter); $right->waitForText('reply=ready', Deadline::afterSeconds(2)); echo "Captured reply=ready on $right->id\n"; } finally { $server->close(); }
Captured reply=ready on %1
Read pane output on an event loop
Pass a LibTmux\Transport\RevoltRunner to the server to watch the panes in one
observed session. Install the optional driver in the application.
Run the live example
$ composer require revolt/event-loop:^1
Use matching tmux 3.7, 3.7a or 3.8 clients and daemons for live output. Ordinary commands and retained jobs work from tmux 3.3a. Qualified operations
For queue sizes and redraw conditions, see the subscription reference. Subscription limits · Loss reasons
Work with a running server
- Collect a short-lived program’s final screen and exit status. Retain a program
- Open a borrowed handle with an explicit socket and inspect how it was selected. Discovery and ownership
- Save a typed filter and apply it to another snapshot. Filter exchange
- Link observed windows and select sessions by their panes. Link an observed window · Shared windows and nested filters
- Inspect split geometry and placement. Read a layout
- Inspect a live query plan and verify its pane candidates with tmux. Query planning
- Execute a preflighted batch and read its per-command replies. Batch receipts
- Refresh a selection after the daemon at an endpoint changes. Recover a reference
On PHP 8.5, run composer install and composer check in the checkout.
Contributor guide
- Consult the PHP API, field catalogue and capability manifest for available operations.
- Closing an owned handle stops its daemon. A borrowed handle leaves its daemon
running. On a borrowed socket that cannot be pinned, snapshots support
inspection and exact actions raise
UnverifiableTarget. - A live subscription returns pane bytes on qualified client and daemon pairs.
tmux can skip output without a notification. Refresh the screen with
capture()when you need the displayed state. - For the
watchOutput()migration and retained-job behavior, read the changelog. - The PHP port uses the MIT License. The libtmux artwork and shared documentation renderer retain their upstream terms. Artwork sources