Next: , Previous: , Up: Server   [Contents][Index]


8.2 HTTP Requests

There isn’t much here yet. Maybe you can help?

Each HTTP request produces a UserRequest associated with a UserSession. Sessions are tightly coupled with PHP24; an existing PHP session is expected, as identified by the ‘PHPSESSID’ cookie. Sessions are shared via Memcache (see ResilientMemcache).25 If a session is not found (or is invalid), an HTTP 500 status code is returned and the HTTP request is aborted.

Requests are subject to a 120 second timeout, after which the request will be served an HTTP 408 status code. Note that this does not stop background processing—this timeout exists to prevent the user from hanging indefinitely.

If a process intends to perform background processing for any length of time (longer than a few seconds), it should complete the request as quickly as possible and use some other mechanism to report back progress (e.g. polling).

The UserRequest exposes raw request data with minor processing.

Path (#getUri)

The path component of the URI. The method name is unfortunate.

Query data (#getGetData)

Query string processed into a key/value object. Despite the name, this is also populated if non-GET requests contain query strings.

POST data (#getPostData)

POST data processed into an object as if it were a query string (just as #getGetData). Since this requires data that is streamed asynchronously, this method takes a callback that waits for all data to become available; if the data are already available, it is immediately invoked with the processed POST data.

Cookies (#getCookies)

Cookies parsed into a key/value object.

Remote address (#getRemoteAddr)

IP address of the origin of the request. If the server is behind a proxy that sets the ‘X-Forwarded-For’ header, it is used instead.

Host address (#getHostAddr)

Hostname of the server. If the server is behind a proxy that sets the ‘X-Forwarded-Host’ header, it is used instead.

Origin (#getOrigin)

Origin of request. Only available if at lease one of the ‘Origin’ or ‘Referer’ headers are set. This is useful mainly for determining the protocol and host while behind a proxy.

User agent (#getUserAgent)

The user agent string of the request.

Session ID (#getSessionId)

The user’s unique session id (‘PHPSESSID’).

Session ID name (#getSessionIdName)

The name of the cookie from which the session ID originated (hard-coded to ‘PHPSESSID’).

TODO: Document return format and writing response data.


Footnotes

(24)

They don’t have to be—refactoring is needed.

(25)

Via a memcache session handler.


Next: , Previous: , Up: Server   [Contents][Index]