OpenSwoole Hook Native CURL

4.x is outdated, please check the latest version 22.x


Latest version: pecl install openswoole-22.1.2

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_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);
});
Last updated on August 31, 2022