Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 25.x
Latest version:
pecl install openswoole-25.2.0
The Swoole\HTTP\Request
object is passed to the Request
event when running a Swoole HTTP server and contains all the information of a HTTP request that was made to your Swoole server, for example, GET, POST, Cookies, files, headers etc.
The request object is passed to you so that you can interact with the server request and client information. You should not access this object via call-by-reference (use of the &
symbol in PHP) because the object is destroyed afterwards and may lead to undefined object errors, only access it from the event callback, this object is only valid during the lifecycle of the server request, meaning, the request object is destroyed after the request has finished.
You can use the following properties and methods to access the HTTP request and data:
Swoole\HTTP\Request->header
Swoole\HTTP\Request->server
Swoole\HTTP\Request->get
Swoole\HTTP\Request->post
Swoole\HTTP\Request->cookie
Swoole\HTTP\Request->rawcookie
Swoole\HTTP\Request->files
Swoole\HTTP\Request->rawContent
Swoole\HTTP\Request->getContent
Swoole\HTTP\Request->getData
Swoole\HTTP\Request->create
Swoole\HTTP\Request->parse
Swoole\HTTP\Request->isCompleted
Swoole\HTTP\Request->getMethod