plphp
plphp : Embed PHP 8 as an untrusted PostgreSQL procedural language
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 3170 | plphp | plphp | 2.6 |
LANG | PostgreSQL | C |
| Attribute | Has Binary | Has Library | Need Load | Has DDL | Relocatable | Trusted |
|---|---|---|---|---|---|---|
| --s-d-- | No | Yes | No | Yes | no | no |
| Relationships | |
|---|---|
| Need By | bytea_plphp hstore_plphp jsonb_plphp |
| See Also | plruby plperl plpython3u pllua plv8 jsonb_plphp hstore_plphp bytea_plphp |
Packages
| Type | Repo | Version | PG Major Compatibility | Package Pattern | Dependencies |
|---|---|---|---|---|---|
| EXT | PIGSTY | 2.6 |
18 17 16 15 14 | plphp |
- |
| RPM | PIGSTY | 2.6 |
18 17 16 15 14 | plphp_$v |
php-embedded |
| DEB | PIGSTY | 2.6 |
18 17 16 15 14 | postgresql-$v-plphp |
libphp-embed |
| Linux / PG | PG18 | PG17 | PG16 | PG15 | PG14 |
|---|---|---|---|---|---|
| el8.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| el8.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| el9.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| el9.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| el10.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| el10.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| d12.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| d12.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| d13.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| d13.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u22.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u22.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u24.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u24.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u26.x86_64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
| u26.aarch64 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 | PIGSTY 2.6 |
Source
github.com/commandprompt/plPHP
plphp-2.6.tar.gz
Install
Make sure PGDG and PIGSTY repo available:
Install this extension with pig:
Create this extension with:
Usage
Sources:
plphp embeds PHP as an untrusted PostgreSQL procedural language for functions, procedures, triggers, event triggers, and anonymous blocks. Use it only when PHP APIs are worth running with the operating-system privileges of the PostgreSQL server process; it is not a sandboxed language.
Core Workflow
PL/php 2.6 supports PHP 8.1 through 8.4 using the embed SAPI without ZTS and PostgreSQL 11 through 18. Installation and creation require a superuser because the language is deliberately untrusted.
Main Interfaces
spi_exec(...),spi_prepare(...),spi_exec_prepared(...),spi_query(...), and cursor helpers access PostgreSQL through SPI.return_next()emits rows from set-returning functions.spi_commit()andspi_rollback()provide transaction control inside procedures.subtransaction(...)creates a catchable subtransaction boundary.$_TDexposes trigger and event-trigger context.$_SHAREDis session-global storage, while$_SDis private per-function session storage.plphp.on_init,plphp.start_proc, andplphp_modulesinitialize a session interpreter.
The optional jsonb_plphp, hstore_plphp, and bytea_plphp extensions add native transforms. A function must declare TRANSFORM FOR TYPE ... to use a transform; installing a companion does not change every PL/php function automatically.
Security and Operations
A PL/php function can read or write files, open network connections, invoke PHP facilities, and affect anything accessible to the PostgreSQL operating-system account. Only grant function ownership and creation rights to roles trusted like a server administrator. Apply normal SECURITY DEFINER and search_path hardening when a privileged wrapper is unavoidable.
SPI query text, dynamic identifiers, session initialization code, loaded modules, and persistent interpreter state all require review. Long-running PHP code blocks a PostgreSQL backend, and memory retained in $_SHARED or $_SD lasts for the session. Use prepared statements for untrusted values, bound resource use, test cancellation/error paths, and recycle sessions when application code retains excessive state.
Version 2.6 adds per-function $_SD and the binary-safe bytea_plphp transform. PostgreSQL tracks the control version as 2.6 while the source distribution is 2.6.0.