PHPackages                             hexmode/io-info - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. hexmode/io-info

Abandoned → [hexmode/io-mode](/?search=hexmode%2Fio-mode)Library[Utility &amp; Helpers](/categories/utility)

hexmode/io-info
===============

More than just posix\_isatty()

1.0(6y ago)210GPL-3.0-or-laterPHP

Since Jun 23Pushed 6y agoCompare

[ Source](https://github.com/hexmode/IOMode)[ Packagist](https://packagist.org/packages/hexmode/io-info)[ RSS](/packages/hexmode-io-info/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (4)Versions (4)Used By (0)

Library to provide information on any device
============================================

[](#library-to-provide-information-on-any-device)

IOMode is based on a [StackOverflow answer](https://stackoverflow.com/a/11327451) and incorportes that code into a reusable library.

From SO:

> I also needed a slightly more flexible solution than posix\_isatty that could detect:
>
> Is the script being run from the terminal Is the script receiving data via a pipe or from a file Is the output being redirected to a file

Example
-------

[](#example)

This library can be used in the following way:

```
use Hexmode\IOMode;

if ( IOMode::isTTY() ) {
    print "tty\n";
}
if ( IOMode::isFifo() ) {
    print "pipe\n";
}
if ( IOMode::isReg() ) {
    print "regular file (redirection)\n";
}
if ( IOMode::isChr() ) {
    print "character device (normal)\n";
}
if ( IOMode::isDir() ) {
    print "directory (?!?!)\n";
}
if ( IOMode::isBlk() ) {
    print "block device\n";
}
if ( IOMode::isLnk() ) {
        print "symlink\n";
}
if ( IOMode::isSock() ) {
    print "socket\n";
}
```

(This above script is in the included `example/doc1.php`.)

Given the following commands, you’ll get different output:

```
$ php example/doc1.php
tty
character device (normal)
$ echo 1 | php example/doc1.php
pipe
$ mkdir tmp; php example/doc1.php < tmp;rmdir tmp
directory (?!?!)
$ sudo sh -c ‘php example/doc1.php> < /dev/sda1'
block device
```

Using with other handles
------------------------

[](#using-with-other-handles)

In addition to the is\*() static methods that provide information on STDIN, there are methods that can be invoked on a `IOMode` object.

The following code is included as `example/doc2.php`:

```
require( "vendor/autoload.php" );
use Hexmode\IOMode\IOMode;

$stderr = new IOMode( STDERR );
$stdout = new IOMode( STDOUT );
$stdin  = new IOMode( STDIN );

foreach (
	[ "in" => $stdin, "out" => $stdout, "err" => $stderr ] as $label => $io
) {
	if ( $io->TTY() ) {
		print "$label: tty\n";
	}
	if ( $io->Fifo() ) {
		print "$label: pipe\n";
	}
	if ( $io->Reg() ) {
		print "$label: regular file (redirection)\n";
	}
	if ( $io->Chr() ) {
		print "$label: character device (normal)\n";
	}
	if ( $io->Dir() ) {
		print "$label: directory (?!?!)\n";
	}
	if ( $io->Blk() ) {
		print "$label: block device\n";
	}
	if ( $io->Lnk() ) {
		print "$label: symlink\n";
	}
	if ( $io->Sock() ) {
		print "$label: socket\n";
	}
}
```

Given the following commands, you’ll get different output:

```
$ sudo sh -c 'php example/doc2.php < /dev/nvme0n1p1'
in: block device
out: tty
out: character device (normal)
err: tty
err: character device (normal)
$ mkdir tmp; php example/doc2.php < tmp 2> /tmp/t;rmdir tmp
in: directory (?!?!)
out: tty
out: character device (normal)
err: regular file (redirection)
$ example/doc2.php > /tmp/t
$ cat /tmp/t; rm /tmp/t
in: tty
in: character device (normal)
out: regular file (redirection)
err: tty
err: character device (normal)
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2516d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/091004c4b32e573a26383800e11030fc01201119f53a8fa6886aa34e80edb42d?d=identicon)[hexmode](/maintainers/hexmode)

---

Top Contributors

[![hexmode](https://avatars.githubusercontent.com/u/43581?v=4)](https://github.com/hexmode "hexmode (7 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/hexmode-io-info/health.svg)

```
[![Health](https://phpackages.com/badges/hexmode-io-info/health.svg)](https://phpackages.com/packages/hexmode-io-info)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
