Show HN: GNU Grep as a PHP Extension

A new native PHP extension written in C embeds the GNU Grep engine directly, providing high-performance pattern matching and CLI-equivalent search capabilities without the overhead of shell execution.
grep is a greenfield PHP extension project implemented in C and built as a shared object with phpize. This repository keeps the upstream GNU grep source in vendor/grep and builds a native PHP module around a separate extension entrypoint. It is not a PHP userspace wrapper around the grep CLI.
GNU grep is GPLv3-or-later. If this extension links against, embeds, or adapts GNU grep internals, the resulting combined work has GPL implications for distribution. The tree now contains a real PHP extension skeleton including config.m4, php_grep.h, and php_grep.c.
The current implementation exposes GNUGrep\Engine and GNUGrep\Pattern, supporting fixed-string matching, basic/extended regular expressions, and common PHP-style regex shorthands like \d and \w. It supports a substantial slice of grep --help switches including recursive search (-r), binary handling, and result shaping (-n, -c, -o).
Performance can be measured using built-in benchmark tools that compare the extension side-by-side with the standalone GNU grep binary. The ggrep() helper serves as the primary userspace entrypoint, allowing developers to pass CLI-style arguments directly within PHP code for both in-memory strings and filesystem paths.
Source: Hacker News















