Skip to content

HTTP Status Codes

Muhammet Şafak edited this page May 24, 2026 · 1 revision

HTTP Status Codes

InitPHP\HTTP\Message\Response::PHRASES is the lookup table the constructor consults when you don't supply an explicit reason phrase:

CodeReason Phrase
100Continue
101Switching Protocols
102Processing
103Early Hints
200OK
201Created
202Accepted
203Non-Authoritative Information
204No Content
205Reset Content
206Partial Content
207Multi-status
208Already Reported
210Content Different
226IM Used
300Multiple Choices
301Moved Permanently
302Found
303See Other
304Not Modified
305Use Proxy
306Switch Proxy
307Temporary Redirect
308Permanent Redirect
400Bad Request
401Unauthorized
402Payment Required
403Forbidden
404Not Found
405Method Not Allowed
406Not Acceptable
407Proxy Authentication Required
408Request Time-out
409Conflict
410Gone
411Length Required
412Precondition Failed
413Request Entity Too Large
414Request-URI Too Large
415Unsupported Media Type
416Requested range not satisfiable
417Expectation Failed
418I'm a teapot
421Misdirected Request
422Unprocessable Entity
423Locked
424Failed Dependency
425Unordered Collection
426Upgrade Required
428Precondition Required
429Too Many Requests
431Request Header Fields Too Large
451Unavailable For Legal Reasons
500Internal Server Error
501Not Implemented
502Bad Gateway
503Service Unavailable
504Gateway Time-out
505HTTP Version not supported
506Variant Also Negotiates
507Insufficient Storage
508Loop Detected
510Not Extended
511Network Authentication Required

Selecting a custom phrase

Pass a reason explicitly when you need something off-canon:

$response = newResponse(418, [], null, '1.1', "I'm a coffee maker, actually");
$response = $response->withStatus(599, 'Network connect timeout error');

Validation

Status codes are validated against the inclusive range 100..599 by both the constructor (indirectly, via setStatusCode) and by withStatus(). Anything else raises InvalidArgumentException:

newResponse(600); // InvalidArgumentExceptionnewResponse(99); // InvalidArgumentException

Codes outside the table

Codes that aren't in the table get an empty reason phrase. Many proxies and clients tolerate that; some refuse to parse a status line without a phrase. Pick a phrase yourself if you're emitting a non-standard code:

$response = (newResponse())->withStatus(599, 'Network connect timeout error');

v2 → v3 note: 500 phrase typo fix

The 500 entry was previously stored as 'Internal ServerRequest Error' — a copy-paste typo. v3 emits the canonical 'Internal Server Error'. Log-aggregation rules that matched on the literal old string will miss new responses; update them or use the status code instead. See Migration Guide.

Clone this wiki locally