Swoole Hook Native CURL

Notice: the documentation is suitable for PHP extension swoole until v4.7.1, we only support PHP extension openswoole from v4.7.1

The SWOOLE_HOOK_NATIVE_CURL flag will enable coroutine support for the CURL library (libcurl). Support was added in v4.6.0.

You must run --enable-swoole-curl when you install Swoole 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_CURL it is enabled by default with SWOOLE_HOOK_ALL

Example

<?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);
});