PHP
Execute PHP scripts in a secure and isolated sandbox.
This page is about the PHP interpreter environment inside the Riza Code Interpreter API. We have not yet published an API client library for PHP.
Runtime
Riza runs the CGI version of PHP 8.2.6 compiled to WASM. The entire standard library is included.
Because PHP is running in CGI mode (rather than CLI mode) there are a few quirks. For instance there are miscellaneous environment variables set that aren’t meaningful in the context of a standalone script.
We’ve done some work to round off the rough edges, though there are limitations.
Limitations
When PHP is running as a CGI program it doesn’t provide access to the constants
STDIN
, STDOUT
and STDERR
and corresponding
php://stdin
, php://stdout
and php://stderr
I/O
streams. The php://input
and php://output
streams work as expected.
The PHP interpreter also doesn’t populate command line parameters in $argv
when running as a CGI program.
See our roadmap for planned future improvements.
Output
You can write to stdout
with echo
or using the php://output
stream.
Write to stderr
with
error_log
.
<?php
echo "Hello, ";
file_put_contents("php://output", "world!");
error_log("Something went wrong");
?>
Input
You can read from stdin
using the php://input
stream, and access environment
variables using $_ENV
. Unfortunately $argv
isn’t populated.
$input = file_get_contents("php://input");
$foo = $_ENV["FOO"];