Closed jgalvezsoax closed 6 years ago
@jgalvezsoax All global functions or variables are disable in Swoole, like $_GET and $_POST and so on, use PSR-7 Request instead please.
You can not rely on globals when handling async requests. To be honest, it's better to always avoid them.
As said by @huangzhhui, the global variables $_GET
and $_POST
cannot be used using Swoole and should be avoided using a middleware approach with Expressive.
We manage the HTTP request using the PSR-7 standard. $_GET and $_POST are managed by$request->getQueryParams()
and $request->getParsedBody()
, where $request
is a PSR-7 ServerRequestInterface.
Thanks for your time
Hello,
I'm trying to set my Zend Expressive application to work with Swoole through the Expressive Swoole library but I have noticed that global vars $_POST and $_GET are empty in my handlers. Also, $_SERVER miss some important keys (for this I will create another issue).
Although $_GET and $_POST are available into handler with
$request->getQueryParams()
and$request->getParsedBody()
I think, since they are not deprecated by PHP team, sometimes is useful to access them directly, specially when you don't have access toPsr\Http\Message\ServerRequestInterface
objectIn next, I'll do all tests with the next invocation (I will send one get var and one post var)
Inspecting the library I have seen in
SwooleRequestHandlerRunner.php
, in "onRequest", that $_GET and $_POST have no contentBut if I print the SwooleHttpRequest content I can see that both vars exist
So, to have my get and post vars I must do something like this in
SwooleRequestHandlerRunner.php
, in "onRequest", to get them:As I said at the beginning, I think $_GET and $_POST vars should have content in any place of the Zend Application.