OpenSwoole\Coroutine::enableCoroutine ()

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

Declaration

<?php OpenSwoole\Coroutine::enableCoroutine ()

Parameters

Return

Description

Enable the coroutine support.

It is the same as OpenSwoole\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 September 1, 2022