Star RestPHP
Already starred? Check a public GitHub username below. This is not a GitHub login; only the username is remembered on this browser.
Appearance
Already starred? Check a public GitHub username below. This is not a GitHub login; only the username is remembered on this browser.
RestPHP hooks directly into PHP's low-level Server API (SAPI) callbacks to capture outputs in memory with zero standard I/O overhead.
ub_write) In standard CLI PHP, calling echo, print, or outputting inline HTML writes directly to the operating system's standard output (stdout file descriptor). This requires expensive OS system calls (write()).
RestPHP intercepts the SAPI ub_write callback:
/* c/sapi.c */
static size_t restphp_sapi_ub_write(const char *str, size_t str_length) {
return restphp_rs_ub_write(str, str_length);
}In Rust (src/sapi/callbacks.rs), restphp_rs_ub_write appends the bytes directly to the current request's in-memory Vec<u8> response buffer:
http_response_code) When a PHP script sets an HTTP status code:
http_response_code(201); // Created
// or
http_response_code(404); // Not FoundRestPHP's SAPI send_headers callback intercepts the integer code and forwards it to the Axum HTTP engine, which responds to the client with the matching HTTP status line.
header()) Headers set in PHP via header() are captured into a key-value header list:
header("Content-Type: application/json");
header("X-Powered-By: RestPHP");
header("Cache-Control: no-cache");RestPHP automatically translates these headers into Axum HTTP response headers, deduplicating default content types while preserving custom metadata.