[Q] How to get php://input? #627
-
Hi, I am using RR2 for a Phalcon4 application. I wanted to use the getJsonRawBody() Phalcon function, which uses the "php:://input" stream to give raw data. But they are empty. There is nothing. Is it possible to get raw data from RR2? my php worker rr: ...
$worker = RoadRunner\Worker::create();
$psrFactory = new Psr7\Factory\Psr17Factory();
$psr7 = new RoadRunner\Http\PSR7Worker($worker, $psrFactory, $psrFactory, $psrFactory);
while ($req = $psr7->waitRequest()) {
$uriObject = $req->getUri();
$getPathClosure = function () {
return $this->path;
};
$uri=$getPathClosure->call($uriObject);
$decodeRequestUri = $uri;
$_GET['_url']=$uri;
foreach ($req->getQueryParams() as $key => $value) {
$_GET[$key] = $value;
$_POST[$key] = $value;
$_REQUEST[$key] = $value;
}
try {
$resp = new Psr7\Response();
$app->handle($uri);
$content = $app->response->getContent();
$resp->getBody()->write($content);
$psr7->respond($resp);
} catch (\Throwable $e) {
$worker->getWorker()->error((string)$e->getMessage() . PHP_EOL);
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It is not possible to get raw data from RoadRunner using the classic method of PHP://input. Under the roadrunner, input is shared between worker executions and not available for direct read. But, you don't need to do that since you have an instance of PSR-7 request: https://www.php-fig.org/psr/psr-7/#13-streams Use $raw = (string)$req->getBody(); Doesn't Phalcon has Request/Response abstraction? I would much rather recommend you hook into such DTO instead of emulating a classic PHP environment (which is an interesting idea, however). |
Beta Was this translation helpful? Give feedback.
It is not possible to get raw data from RoadRunner using the classic method of PHP://input. Under the roadrunner, input is shared between worker executions and not available for direct read.
But, you don't need to do that since you have an instance of PSR-7 request: https://www.php-fig.org/psr/psr-7/#13-streams
Use
getBody()
stream to read the raw content of the body.Doesn't Phalcon has Request/Response abstraction? I would much rather recommend you hook into such DTO instead of emulating a classic PHP environment (which is an interesting idea, however).