OpenSwoole Hook CURL

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

The OpenSwoole\Runtime::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 OpenSwoole\Runtime::HOOK_NATIVE_CURL instead as since v4.6.0 OpenSwoole supports native CURL.

Example

<?php

co::set(['hook_flags' => OpenSwoole\Runtime::HOOK_CURL]);

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 20, 2022