fix: PHP env PSR-7 format — getBody()->write() instead of return array

This commit is contained in:
“Naeel”
2026-05-19 10:41:46 +04:00
parent 72e5d50cd0
commit 042b1e5046
+6 -6
View File
@@ -450,7 +450,7 @@ function isPrime($n) {
return true;
}
function handler(array $ctx): array {
function handler($ctx) {
global $CONSTS;
$mat = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]];
$data = range(1, 50);
@@ -474,7 +474,7 @@ function handler(array $ctx): array {
'is_prime_97'=> isPrime(97),
'groups_3' => groupByMod(array_slice($data, 0, 30), 3),
];
return ['statusCode' => 200, 'body' => json_encode($result)];
$ctx["response"]->getBody()->write(json_encode($result));
}
PHPEOF
create_json "php" "$FN_BIG_PHP" "${TMP}/big_php.php"
@@ -564,8 +564,8 @@ function fib($n) {
if ($n < 2) return $n;
return fib($n-1) + fib($n-2);
}
function handler(array $ctx): array {
return ['statusCode' => 200, 'body' => 'cpu-burn-php:' . fib(28)];
function handler($ctx) {
$ctx["response"]->getBody()->write('cpu-burn-php:' . fib(28));
}
PHPEOF
create_json "php" "$FN_CPU_PHP" "${TMP}/cpu_php.php"
@@ -711,8 +711,8 @@ python3 - > "${TMP}/arc-php.zip" << 'EOF'
import zipfile, io, sys
buf = io.BytesIO()
code = """<?php
function handler(array $ctx): array {
return ['statusCode' => 200, 'body' => json_encode(['tag' => 'archive-php-ok', 'fib25' => 75025])];
function handler($ctx) {
$ctx[\"response\"]->getBody()->write(json_encode(['tag' => 'archive-php-ok', 'fib25' => 75025]));
}
"""
with zipfile.ZipFile(buf, 'w', zipfile.ZIP_DEFLATED) as zf: