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->get(string $path): void
The URL path to send a GET request to. For example /user/account
or /index.php
. Only set the path here not the protocol or domain name like http://domain
.
None
Initiate a HTTP client GET request using the specified URL path.
When you use this method it will switch to use
GET
for you, no need to usesetMethod
<?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',
]);
// First GET request
$client->get('/home/contact');
var_dump($client->body);
// Second GET request
$client->get('/index.php');
var_dump($client->body);
$client->close();
});