OpenSwoole Hook Native CURL

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

The OpenSwoole\Runtime::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-hook-curl when you install OpenSwoole to enable CURL support. By enabling this it will automatically set the OpenSwoole\Runtime::HOOK_NATIVE_CURL flag and turn off SWOOLE_HOOK_CURL.

When using OpenSwoole\Runtime::HOOK_NATIVE_CURL it is enabled by default with SWOOLE_HOOK_ALL

Example

<?php

Co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_ALL]);

Co::run(function()
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://openswoole.com");
    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 September 22, 2022