Skip to content
PHP API

PHP API

Everything ePHPm adds to the PHP environment, in one place: the native functions and classes it registers, the $_SERVER variables it injects, and the ini settings it writes or leaves at PHP’s defaults. The guides linked from each section have the details and examples. The source of truth is crates/ephpm-php/ephpm_wrapper.c (function tables and arginfo) and crates/ephpm-php/src/request.rs ($_SERVER).

The SAPI

PHP_SAPI / php_sapi_name() is "ephpm" when serving requests and "cli" under ephpm php.

Every function below is registered in both contexts, so function_exists() tells you that you are running under ePHPm, not which features are configured. Under ephpm php, the KV functions are present but not connected to a store (see KV from PHP), the worker functions are inert, and the database functions work only with --site (see ephpm php).

Native functions

KV store — ephpm_kv_*

ephpm_kv_get, ephpm_kv_set, ephpm_kv_setnx, ephpm_kv_del, ephpm_kv_del_if_eq, ephpm_kv_exists, ephpm_kv_incr, ephpm_kv_decr, ephpm_kv_incr_by, ephpm_kv_expire, ephpm_kv_ttl, ephpm_kv_pttl, ephpm_kv_flush_all, ephpm_kv_wait.

Since v0.13: strings and keys — ephpm_kv_mget, ephpm_kv_mset, ephpm_kv_getdel, ephpm_kv_getex, ephpm_kv_persist, ephpm_kv_set_if_eq, ephpm_kv_append, ephpm_kv_strlen, ephpm_kv_type, ephpm_kv_scan; hashes — ephpm_kv_hget, ephpm_kv_hset, ephpm_kv_hsetnx, ephpm_kv_hmget, ephpm_kv_hgetall, ephpm_kv_hkeys, ephpm_kv_hvals, ephpm_kv_hdel, ephpm_kv_hexists, ephpm_kv_hlen, ephpm_kv_hincr_by, ephpm_kv_hexpire, ephpm_kv_httl, ephpm_kv_hpttl, ephpm_kv_hpersist. Code that must also run on older ePHPm should guard them with function_exists().

Signatures, return values and edge cases: KV from PHP — Function reference.

Embedded database — ephpm_db_*

ephpm_db_query, ephpm_db_execute, ephpm_db_run, ephpm_db_columns, ephpm_db_in_transaction, ephpm_db_available, ephpm_db_errno, ephpm_db_error, ephpm_db_cursor_open, ephpm_db_cursor_fetch, ephpm_db_cursor_close.

See Database from PHP. The bridge’s reserved error codes (2000–2004) are exception codes, not PHP constants; compare against the integers. The ephpm_db_cursor_* streaming functions were added in v0.20.0; feature-detect them with function_exists() if you support older servers.

WebSockets — ephpm_ws_* (experimental)

ephpm_ws_send, ephpm_ws_connection_send, ephpm_ws_subscribe, ephpm_ws_connection_subscribe, ephpm_ws_unsubscribe, ephpm_ws_connection_unsubscribe, ephpm_ws_broadcast, ephpm_ws_close, ephpm_ws_connection_close.

See WebSockets — Function reference. Misuse throws a plain \Exception with code 0.

Worker mode — Ephpm\Worker\*

SymbolSignature
Ephpm\Worker\take_request()(): ?Ephpm\Worker\Envelope
Ephpm\Worker\send_response()(int $status, array $headers, string $body): void
Ephpm\Worker\send_response_stream()(int $status, array $headers, resource $body): void
class Ephpm\Worker\EnvelopeserverVars(), headers(), cookies(), query(), parsedBody(), files(), bodyStream(), rawBody()

Registered by the internal module ephpm_worker. Outside worker mode take_request() returns null immediately and the send_response*() functions do nothing. See Worker Mode.

PHP middleware — ephpm_middleware_config()

ephpm_middleware_config(): ?string returns the running PHP middleware mount’s config table as a JSON string, or null when the script is not running as a PHP middleware (or the mount has no config). See Native Middleware — The PHP lane.

CLI only — under ephpm php

cli_set_process_title() and cli_get_process_title(), plus the STDIN, STDOUT and STDERR constants, exactly as php-cli provides them. They do not exist while serving requests. See ephpm php.

IDE stubs

The ephpm/db package ships IDE/static-analysis stubs for ephpm_db_*, ephpm/cache for every ephpm_kv_* function (stubs/ephpm-kv.stub.php), and ephpm/worker for the worker API. Never autoload a stub at runtime: the functions are native, and redefining them is a fatal error.

Session save handler — ephpm

session.save_handler = ephpm stores $_SESSION in the KV store. It is registered in every mode but not enabled by default. See Sessions.

$_SERVER variables

ePHPm builds $_SERVER from scratch for every request. Nothing it injects is a process environment variable: getenv() does not see any of the variables below. Read them from $_SERVER. (A process-wide environment would be shared by every tenant’s threads.)

VariablesWhen
REQUEST_METHOD, REQUEST_URI, SCRIPT_FILENAME, SCRIPT_NAME, PHP_SELF, DOCUMENT_ROOT, SERVER_NAME, SERVER_PORT, SERVER_PROTOCOL, QUERY_STRING, REMOTE_ADDR, REMOTE_PORTEvery request. See $_SERVER Variables.
SERVER_SOFTWAREEvery request. ePHPm/<version>, the same build version ephpm --version reports (the release tag on official builds, the crate version on local builds).
GATEWAY_INTERFACE = CGI/1.1, REDIRECT_STATUS = 200Every request.
HTTPS = onRequests that arrived over TLS.
AUTH_TYPE, PHP_AUTH_USER, PHP_AUTH_PW, PHP_AUTH_DIGESTDerived from an Authorization header. See HTTP Authentication Variables.
HTTP_*, CONTENT_TYPE, CONTENT_LENGTHOne per request header, CGI-style.
DB_CONNECTION, DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD, DATABASE_URL[db.mysql] or [db.postgres] with inject_env = true (the default). Proxy mode does not set DB_DATABASE or DB_USERNAME.
The above plus DB_DATABASE and DB_USERNAMEPer-site embedded databases ([server] sites_dir + [db.sqlite]): each site’s own credentials. See Multi-tenant pdo_mysql.
EPHPM_REDIS_HOST, EPHPM_REDIS_PORT, EPHPM_REDIS_USERNAME, EPHPM_REDIS_PASSWORD[kv.redis_compat] enabled = true + [kv] secret + [server] sites_dir. See KV from PHP — Multi-tenant note.
EPHPM_NODE_IDWhen this node has an identity: the running gossip node’s id with [cluster] enabled = true, otherwise [cluster] node_id if it is set. Absent when neither applies.
WS_EVENT, WS_CONNECTION_ID, WS_OPCODEWebSocket events only. See WebSockets.

No entry limit. Every variable is registered, however many request headers arrive. (Before this was fixed, ePHPm kept only the first 128 entries; because the ePHPm-injected variables are registered after the request headers, a header-heavy request could lose a site’s database credentials.)

ini settings

Where PHP’s configuration comes from

ePHPm generates a php.ini at startup and points PHP at it, so a system php.ini is never read. Configure PHP through [php] ini_overrides, [php] ini_file (its contents are copied into the generated file), or ini_set() at runtime. See [php].

What ePHPm writes

In the order they appear in the generated file, so later lines win:

  1. display_errors, display_startup_errors and log_errors: Off/Off/On under ephpm serve, On/On/On under ephpm dev. See Where PHP errors go.
  2. extension=<entry> — one per [php] extensions entry.
  3. The contents of [php] ini_file, if set.
  4. opcache.validate_timestamps (always), plus the autotuned OPcache, memory_limit, realpath-cache and assertion lines. See Resource-aware autotuning. On Windows, also opcache.cache_id=ephpm-<pid>, which gives each process a private OPcache segment (#362).
  5. max_execution_time — on builds with per-thread execution timers (not Windows).
  6. Every [php] ini_overrides line except disable_functions.
  7. disable_functions — your list, unioned with ePHPm’s multi-tenant baseline in vhost mode (in single-site mode your list is emitted alone).
  8. mysqli.allow_persistent=0, pgsql.allow_persistent=0, odbc.allow_persistent=0 and, unless cluster OPcache invalidation is on, opcache.restrict_api — with the multi-tenant hardening preset only. See Multi-tenant hardening.

In multi-tenant mode, open_basedir, sys_temp_dir, upload_tmp_dir, session.save_path and a site’s auto_prepend_file are also set per request. See Virtual Hosts.

What ePHPm leaves at PHP’s defaults

error_reporting keeps PHP’s default of E_ALL. Under ephpm serve, display_errors is off (item 1 above), so warnings, notices and fatal errors go to ePHPm’s log, not into the HTTP response. Under ephpm dev they are displayed as plain text (the embed SAPI sets html_errors=0), including file paths:

Warning: Undefined variable $x in /var/www/app/index.php on line 3

Through v0.11.3 ePHPm set no display_errors line, so this display was on under serve too.

The embed SAPI’s other built-in values also apply: output_buffering=0, implicit_flush=1, register_argc_argv=1 and max_input_time=-1. PHP applies these after the generated php.ini, so ini_overrides and ini_file cannot change them; implicit_flush can still be changed at runtime with ini_set().