Closed sy-records closed 3 years ago
// composer require guzzlehttp/guzzle include __DIR__ . '/vendor/autoload.php'; use GuzzleHttp\Client; Swoole\Runtime::enableCoroutine(SWOOLE_HOOK_ALL); go(function () { $url = 'https://httpbin.org/get'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_WRITEFUNCTION, function ($ch, $data) { echo 'Data: ' . $data; return strlen($data); }); $data = curl_exec($ch); curl_close($ch); var_dump($data); // // $client = new Client(); // $url = 'http://baidu.com'; // $res = $client->request('GET', $url); // var_dump($res->getBody()->getContents()); });