phasync
CurlResponse / getStatusCode

Method

CurlResponse::getStatusCode

Return the HTTP status code, waiting for the headers to arrive.

Description#

public CurlResponse::getStatusCode(): int

A 404 or 500 is returned as a number and throws nothing.

Return values#

int

Errors / Exceptions#

ExceptionWhen
NetworkExceptionWhen no response headers arrived because of a network failure
RequestExceptionWhen the request is invalid
ClientExceptionFor any other failure, such as too many redirects

Examples#

Example 1
try {
    $status = $client->get('https://example.com/')->getStatusCode();
} catch (\Psr\Http\Client\NetworkExceptionInterface $e) {
    // connection refused, DNS failure, timeout: $e->getCode() is cURL's error number
}

See also#