trismegiste/prolog
A Prolog interpreter written in PHP. Embed logic programming and rule-based reasoning directly in your PHP applications using familiar Prolog syntax, unification, backtracking, and query solving—no external extensions required.
What the package is. trismegiste/prolog is a pure-PHP implementation of a Prolog engine built around the Warren Abstract Machine (WAM): Prolog source clauses are parsed and compiled to WAM instructions, which are then executed by a PHP-implemented virtual machine (unification, backtracking, choice points, cut). It is not a binding to SWI-Prolog or FFI — it is an interpreter written in userland PHP.
Architecture fit.
symfony/expression-language or a lightweight rules engine will be cheaper to own, test, and staff.RuleEngine interface) so the inference core is swappable for a SWI-Prolog sidecar if scale or correctness demands it..pl files — that is a governance decision, not just a technical one: rule authorship, review, and versioning move outside normal PHP code review.Integration feasibility.
Trismegiste\Prolog), no PHP extensions or compiled artifacts required — deploys on standard Laravel hosting, containers, and restricted environments where exec/FFI to SWI-Prolog is unavailable.LICENSE file and its terms (GPL vs. MIT materially changes the decision for a proprietary product), and whether composer.json declares sane stability and autoload config.Technical risk.
max_execution_time or memory_limit kills the worker — a fatal error, not an exception, so it is not catchable in-request.false, distinguishing "no solution" from "malformed rule" from "unsupported built-in" is often manual. Traceability from a failed query back to a specific clause is the main developer-experience gap.Key questions to answer before commitment.
findall/bagof, string handling?pcntl_alarm/supervisor timeouts?Stack fit.
PrologEngineFactory in a PrologServiceProvider; expose a PrologService that owns clause loading, query execution, and result normalization into plain PHP arrays/DTOs..pl sources in resources/prolog/ (versioned, code-reviewed) and publish config via config/prolog.php for paths, step limits, and cache TTL.try/catch plus a hard step/time budget enforced by the wrapper — never let an unguarded query reach a web request path.ShouldQueue, with $timeout and $tries), returning results via broadcast or polling. This converts fatal-error risk into a retryable job failure.prolog:compile (parse and serialize clauses for caching), prolog:query (REPL-ish debugging for developers and rule authors).Migration path.
Compatibility.
php constraint satisfies your Laravel version's floor (Laravel 10/11 already require 8.1/8.2). Dependency conflicts are unlikely given it is standalone, but confirm it does not pull in deprecated or abandoned transitive packages.ini_set side effects that could interfere with Octane or long-running workers; if the engine is not stateless, do not register it as a singleton under Octane — use a scoped binding or per-job instantiation.ErrorExceptions.Sequencing.
RuleEngine interface, result DTOs, error contract, and the rule-authoring/review process.Maintenance.
^ ranges, and vendor or fork if upstream goes quiet. The code footprint is small enough that a fork is realistic, but only if someone on the team can read WAM-shaped code..pl files need ownership, review, tests, and a changelog just like application code. Budget for that explicitly.Support.
Scaling.
Failure modes.
max_execution_time; symptom is a 504, not a stack trace.false or wrong bindings with no signal. This is the most dangerous mode because it looks like a legitimate negative answer.Ramp-up.
TPM recommendation. At a 0.35 confidence score, this is a contained-experiment candidate, not a platform commitment. It is technically viable as an embedded, isolated reasoning module in a non-critical path behind a swappable interface, with hard resource limits and a queue-based execution model. It is not appropriate for latency-sensitive request paths, large knowledge bases, or anything where a hung worker or a silently wrong false is unacceptable. Gate adoption on the license check, a real benchmark against alternatives (SWI-Prolog sidecar, a PHP rules engine), and an explicit answer to "who maintains the rules, and who maintains the library when upstream stops."
How can I help you explore Laravel packages today?