Download the PHP package iliaal/statgrab without Composer

On this page you can find all versions of the php package iliaal/statgrab. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package statgrab

statgrab

Tests Version License: PHP-3.01 Follow @iliaa

A native PHP extension wrapping libstatgrab, the cross-platform system-statistics library. Originally released to PECL in 2006 against libstatgrab 0.6; the 2.0.0 line is a full modernization for the PHP 8.0+ era against libstatgrab 0.92+.

Supports PHP 8.0 through 8.5 on glibc Linux, musl, macOS, and *BSD.

⚖️ Why native

Without an extension, reading system stats from PHP means one of these:

statgrab calls libstatgrab in-process. libstatgrab handles the per-OS path (Linux /proc, FreeBSD kvm, macOS host_* APIs) and is packaged for Debian/Ubuntu, Homebrew, and FreeBSD. The 2006 PECL binding never shipped a PHP 8 build, and its quirks (stringified counters, swapped page-stat keys, a flat name_list for users) made it awkward even when you could compile it.

✨ Key features

Feature Notes
Cross-platform glibc Linux, musl, macOS, FreeBSD
Procedural + OO API 2006 sg_* function names preserved; modern Statgrab class on top
Bundled libstatgrab option Vendored 0.92.1 with local patches (see vendor/libstatgrab/LOCAL_PATCHES.md); resulting .so has no runtime dependency on libstatgrab.so
Modern types Counters returned as 64-bit int, not stringified numbers
Modern PHP errors E_WARNING on library failure, ArgumentCountError for arg-count violations
BC-preserved 2006 names Drop-in for callers of the original PECL extension, except the 2.0 BC breaks listed below

🚀 Quick start

PIE (recommended on PHP 8.x)

PIE is the PHP Foundation's PECL successor. It installs from Packagist and builds against the active php-config. Install libstatgrab first (package names are under From source), then:

Then add extension=statgrab to your php.ini.

PECL

statgrab is also on PECL:

From source

Then add extension=statgrab to your php.ini.

config.m4 finds libstatgrab through pkg-config first, then falls back to a path probe (/usr and /usr/local). Pass --with-statgrab=<prefix> to point at a custom install.

Bundled libstatgrab (statically linked, leak-fixed)

The repo carries a vendored copy of libstatgrab 0.92.1 under vendor/libstatgrab/ with local patches (see vendor/libstatgrab/LOCAL_PATCHES.md) for a process-exit leak, a stack buffer overflow in the diff getters, uninitialised process session IDs, and a heap buffer overflow when parsing Linux process command lines, which upstream has not released yet, plus a local fix for two undefined shifts. A Git checkout does not include the generated libstatgrab configure script, so generate it with autoreconf first. This requires Autoconf, Automake, and Libtool in addition to the usual C compiler, Make, and PHP development tools (on Debian/Ubuntu, install autoconf automake libtool php-dev build-essential pkg-config). To use it:

The resulting .so has no libstatgrab.so runtime dependency. PHP's make clean also deletes the bundled libstatgrab.a; after it, run make -C vendor/libstatgrab before make, or the build stops.

The vendored libstatgrab tree stays LGPL 2.1+ (see LICENSE.libstatgrab); the extension code stays PHP-3.01 (see LICENSE). Dynamic-link or static-link, neither license infects the other.

API

Procedural

The 2006 function names are preserved.

CPU sampling and timing

With bundled libstatgrab 0.92.1 on the supported Unix platforms, CPU results carry the legacy previous_run key with these meanings (in whole seconds). The corresponding Statgrab methods use the same behavior:

The CPU_PERCENT_* names above are Statgrab class constants. CPU sampling state is shared by both APIs within the calling thread: cumulative CPU calls also replace its baseline. Whole-second wall-clock differences may be zero for rapid samples and can be affected by system clock adjustments.

To measure a fresh interval, call sg_cpu_totals(), wait for the desired interval, then call sg_cpu_percent_usage(Statgrab::CPU_PERCENT_NEW_DIFF). Avoid other CPU sampling calls between them. sg_snapshot() is a no-op in bundled libstatgrab on Unix; it does not seed or reset these counters. System-linked builds use the installed libstatgrab's backend behavior.

Rapid consecutive CPU diff samples can contain no elapsed CPU ticks. In that case CPU percentages are 0.0 rather than NaN, so samples remain JSON-encodable; wait between samples to measure meaningful utilization.

sg_diskio_stats() / sg_diskio_stats_diff(), sg_network_stats() / sg_network_stats_diff(), and sg_network_iface_stats() key rows by device/interface name; a duplicate name (multipath/LVM can repeat one) falls back to a numeric key instead of overwriting the earlier row.

proc_title from sg_process_stats() / processes() holds at most 4096 bytes of each process's command line. Any local user controls their own argv, so the cap keeps a few huge command lines from exhausting memory_limit. libstatgrab still reads each full command line into the C heap while it collects the list, so that memory is used transiently outside memory_limit. When the cut lands inside a UTF-8 sequence, the title ends before that sequence, so a truncated title can be up to 3 bytes shorter.

The valid-filesystems filter is process-wide in libstatgrab, not per-request. In NTS builds it persists across requests in long-lived workers such as FPM. Under a threaded (ZTS) SAPI, sg_set_valid_filesystems() in one request also changes the sg_fs_stats() filter for every other thread. The extension serializes sg_fs_stats(), sg_valid_filesystems(), and sg_set_valid_filesystems() (and their Statgrab methods) across threads so concurrent calls are memory-safe. A hung mount that blocks sg_fs_stats() therefore stalls all of these calls in every thread.

Object-oriented

Class constants:

Errors

Library-side errors emit E_WARNING with the libstatgrab error string and code, and the function returns false. The OO surface follows the same convention. Argument-count violations on no-arg functions throw ArgumentCountError.

sg_set_valid_filesystems() and Statgrab::setValidFilesystems() throw instead of warning on bad input: ValueError on an empty array or an entry containing NUL bytes, TypeError on a non-string entry. A libstatgrab runtime failure from the setter (or any other stat call) takes the usual warning and false path. Call sg_error_details() / Statgrab::errorDetails() after a false return for the code, message, errno, and arg.

Notable 2.0 BC breaks

See CHANGELOG.md for the full list.

🔗 Native PHP extensions

Companion native PHP extensions:

License

PHP License 3.01.


Follow @iliaa on X • Blog

If this saved you from parsing /proc by hand, ⭐ star it!


All versions of statgrab with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package iliaal/statgrab contains the following files

Loading the files please wait ...