Swoole Hook 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_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 SWOOLE_HOOK_NATIVE_CURL instead as since v4.6.0 Swoole supports native CURL.

Example

<?php

Co::set(['hook_flags' => SWOOLE_HOOK_CURL]);

Co\run(function()
{
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, "http://www.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);
});