Search by

libtmux / libtmux-php

git-pull

tmux client library for PHP 8.4+

Package info

github.com/libtmux/libtmux-php

pkg:composer/libtmux/libtmux-php

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.0.1-alpha.1 2026-12-05 11:29 UTC

This package is auto-updated.

Last update: 2026-12-05 12:17:13 UTC


README

libtmux for PHP

libtmux for PHP

PHP package checks Packagist version MIT License

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

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