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
The SWOOLE_HOOK_CURL
flag will enable coroutine support for the CURL library. Support was added in v4.4.0+
.
This includes support for:
curl_init
curl_setopt
curl_exec
curl_multi_getcontent
curl_setopt_array
curl_error
curl_getinfo
curl_errno
curl_close
curl_reset
However, it is now recommended to use
SWOOLE_HOOK_NATIVE_CURL
instead as sincev4.6.0
OpenSwoole supports native CURL.
<?php
Co::set(['hook_flags' => SWOOLE_HOOK_CURL]);
Co\run(function()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://openswoole.com/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
});