Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 22.x
Latest version:
pecl install openswoole-22.1.2
<?php Swoole\Coroutine\Http\Client->getStatusCode(): int|bool
None
An integer of the HTTP status code or false
if something went wrong.
Get the HTTP status code returned from the remote server. If the status code is negative it means there is a problem with the connection.
-1
: SWOOLE_HTTP_CLIENT_ESTATUS_CONNECT_FAILED
$client->errCode
to get the specific network error code.-2
: SWOOLE_HTTP_CLIENT_ESTATUS_REQUEST_TIMEOUT
-3
: SWOOLE_HTTP_CLIENT_ESTATUS_SERVER_RESET
-4
: SWOOLE_HTTP_CLIENT_ESTATUS_SEND_FAILED
$client->errCode
for specific error code and message.<?php
use Swoole\Coroutine\HTTP\Client;
Co\run(function()
{
$client = new Client('127.0.0.1', 80);
$client->setHeaders([
'Host' => "localhost",
"User-Agent" => 'Chrome/49.0.2587.3',
'Accept' => 'text/html,application/xhtml+xml,application/xml',
'Accept-Encoding' => 'gzip',
]);
$client->set(['timeout' => 1]);
$client->setDefer(true);
$client->get('/index.php');
var_dump($client->getStatusCode());
$client->close();
});
You can also access the HTTP client status code by using the class property directly like so:
Swoole\Coroutine\Http\Client->statusCode: int
echo $client->statusCode;