Join 4,000+ others and never miss out on new tips, tutorials, and more.
4.x is outdated, please check the latest version 25.x
Latest version:
pecl install openswoole-25.2.0
The SWOOLE_HOOK_NATIVE_CURL flag will enable coroutine support for the CURL library (libcurl). Support was added in OpenSwoole v4.6.0.
You must run --enable-swoole-curl when you install OpenSwoole to enable CURL support. By enabling this it will automatically set the SWOOLE_HOOK_NATIVE_CURL flag and turn off SWOOLE_HOOK_CURL.
When using
SWOOLE_HOOK_NATIVE_CURLit is enabled by default withSWOOLE_HOOK_ALL
<?php
Co::set(['hook_flags' => SWOOLE_HOOK_ALL]);
Co\run(function()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://swoole.co.uk");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
var_dump($result);
});