Swoole\Coroutine::enableCoroutine ()

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


Latest version: pecl install openswoole-22.1.2

Declaration

<?php Swoole\Coroutine::enableCoroutine ()

Parameters

Return

Description

Enable the coroutine support.

It is the same as Swoole\Runtime::enableCoroutine().

Since version 4.1.0, it enables coroutine on any IO libraries using php_stream.

Supported libraries:

  • Redis
  • mysqlnd, PDO, mysqli
  • SOAP
  • file_get_contents, fopen
  • stream_socket_client
  • fsockopen
  • curl
  • fread, fwrite, fgets

Not supported:

  • MySQL with libmysqlclient
  • curl with libcurl
  • MongoDB with mongo-c-client
  • pdo_pgsql, pdo_ori, pdo_odbc, pdo_firebird

Example

<?php
Swoole\Coroutine::enableCoroutine();

Co\run(function () {
    $redis = new redis;
    $retval = $redis->connect("127.0.0.1", 6379);
    var_dump($retval, $redis->getLastError());
    var_dump($redis->get("key"));
    var_dump($redis->set("key", "value2"));
    var_dump($redis->get("key"));
    $redis->close();
});
Last updated on August 31, 2022