PHP Sandbox
-Test your PHP code snippets in a safe, isolated environment. Type your code, hit run, and see the output instantly.
-Output
-
-
-
- Errors
-
-
- diff --git a/sandbox.php b/sandbox.php index 95f1199..94bd14d 100644 --- a/sandbox.php +++ b/sandbox.php @@ -1,6 +1,11 @@ '; + } + $descriptorspec = [ 0 => ["pipe", "r"], // stdin 1 => ["pipe", "w"], // stdout @@ -11,116 +16,4 @@ function execute_php_code($code) { if (is_resource($process)) { fwrite($pipes[0], $code); - fclose($pipes[0]); - - $stdout = stream_get_contents($pipes[1]); - fclose($pipes[1]); - - $stderr = stream_get_contents($pipes[2]); - fclose($pipes[2]); - - proc_close($process); - - return ['stdout' => $stdout, 'stderr' => $stderr]; - } - return false; -} - -$code = ''; -$result_output = ''; -$result_error = ''; - -if ($_SERVER["REQUEST_METHOD"] == "POST") { - $code = $_POST['code'] ?? ''; - if (!empty($code)) { - $execution_result = execute_php_code($code); - if ($execution_result !== false) { - $result_output = $execution_result['stdout']; - $result_error = $execution_result['stderr']; - } else { - $result_error = "Failed to execute the code."; - } - } else { - $result_output = "No code to run."; - } -} - -?> - - -
- - -Test your PHP code snippets in a safe, isolated environment. Type your code, hit run, and see the output instantly.
-
-
-
-
-
-