Join 4,000+ others and never miss out on new tips, tutorials, and more.
Latest version:
pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5
<?php OpenSwoole\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 OpenSwoole\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();
});