fqqdk/igraph (0.1.0)

Published 2026-07-04 14:33:54 +00:00 by fqqdk in fqqdk/php-igraph

Installation

{
	"repositories": [{
			"type": "composer",
			"url": ""
		}
	]
}
composer require fqqdk/igraph:0.1.0

About this package

The igraph graph-algorithms C library as a PHP extension. Exposes igraph_is_dag($n, $edges) for directed-acyclic-graph testing (and igraph_version()); the graph API surface grows from here.

igraph

The igraph graph-algorithms C library packaged as a PHP extension — a sibling to planarity, built to the same recipe: a tiny, audited wrapper (igraph.c, the only code we author) over a vendored C library, with a .phpt suite, a reproducible Docker build, Forgejo CI, and a Composer php-ext package.

API

igraph_is_dag(int $n, array $edges): bool
//   $n     — vertex count; vertices are 0 .. n-1.
//   $edges — list of [u, v] integer pairs, each a DIRECTED edge u -> v (0-based). Multigraphs are
//            accepted: parallel edges are fine; a self-loop (u -> u) or an anti-parallel pair
//            (u -> v and v -> u) forms a cycle. Nothing is dropped.
//   →  bool — true iff the directed graph is acyclic (a DAG: no directed cycle). The empty and any
//             edgeless graph are DAGs.
//   throws ValueError on malformed input (endpoint out of range, n out of range, bad edge shape).

igraph_version(): string
//   → the linked (vendored) libigraph version, e.g. "1.0.1".

The input shape mirrors the sibling planarity($n, $edges). More igraph capabilities will be added behind the same tiny-surface, single-cleanup-path discipline.

How igraph is vendored

Unlike planarity (a flat set of .c files listed in config.m4), igraph is a large CMake library with generated headers and bundled dependencies, so we pin it as a git submodule (vendor/igraph @ tag 1.0.1) and drive its own build: config.m4 runs cmake to produce a self-contained static libigraph.a (all deps internal), then links it into the extension. See vendor/VENDOR.md for the full rationale and the licensing note.

License: igraph is GPL-2.0-or-later; because we statically link it, so is this extension.

Build (host)

Requires cmake, flex, bison, libxml2-dev, and a C++ compiler in addition to the usual phpize toolchain (see vendor/VENDOR.md). Fetch the submodule first:

git submodule update --init vendor/igraph
phpize && ./configure --enable-igraph && make

The first ./configure builds the vendored igraph static library (several minutes); it is cached by the presence of vendor/igraph-build/src/libigraph.a, so re-make is fast.

Two PHP installs may coexist on a dev host. The extension loads in the distro php (/usr/bin/php8.5); a static /usr/local/bin/php build can have dynamic loading disabled. Use the binary that loads it:

/usr/bin/php8.5 -d extension="$(pwd)/modules/igraph.so" --ri igraph

Tests

The behavioural suite is .phpt (PHP's native extension test format) under tests/, run by the run-tests.php harness that phpize drops in — no phpunit/composer needed.

make test                      # after phpize && ./configure --enable-igraph && make

On a host without the full build toolchain, the bundled image builds the extension and runs the suite:

docker build -t php-igraph .
docker run --rm php-igraph                 # runs `make test`

Dependencies

Dependencies

ID Version
php >=8.1

Keywords

igraph graph network algorithms php-extension
Details
Composer
2026-07-04 14:33:54 +00:00
0
fqqdk
GPL-2.0-or-later
5.6 MiB
Assets (1)
Versions (24) View all
0.24.0 2026-07-06
0.20.0 2026-07-06
0.19.0 2026-07-06
0.23.0 2026-07-06
0.22.0 2026-07-06