swoole-src: Fatal error: go(): async-io must be used in PHP CLI mode

I have error Fatal error: go(): async-io must be used in PHP CLI mode

  1. What did you do? If possible, provide a simple script for reproducing the error. Swoole\Runtime::enableCoroutine(); $s = microtime(true); for ($c = 50; $c--;) { go(function () { $mysqli = new Mysqli('127.0.0.1', 'xxx', 'xxx', 'xxx'); $statement = $mysqli->query('SELECT * FROM (SELECT * FROM shoutboxORDER BYsid) AS shoutboxORDER BYshoutbox.sid ASC'); $i = 0; while ($test = $mysqli->fetch_array($statement)) { echo $i . ' - uid: ' . $test['uid'] . '<br>'; $i++; } }); } Swoole\Event::wait(); echo 'use ' . (microtime(true) - $s) . ' s';

  2. What did you expect to see?

Just counting $i and see how it’s performance on my server with swoole

  1. What did you see instead?

Fatal error: go(): async-io must be used in PHP CLI mode

  1. What version of Swoole are you using (show your php --ri swoole)? swoole swoole support => enabled Version => 4.2.9 Author => Swoole Group[email: team@swoole.com] coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => 1.35.1 pcre => enabled zlib => enabled mutex_timedlock => enabled pthread_barrier => enabled futex => enabled mysqlnd => enabled async_redis => enabled Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.aio_thread_num => 2 => 2 swoole.display_errors => On => On swoole.use_namespace => On => On swoole.use_shortname => On => On swoole.fast_serialize => Off => Off swoole.unixsock_buffer_size => 8388608 => 8388608

  2. What is your machine environment used (including version of kernel & php & gcc) ?

CentOS 7.x Directadmin with PHP, 7.2 nginx as reverse proxy and php-fpm (I guess it’s the problem but how to get it worked?) gcc version 4.8.5 20150623 Linux 3.10.0-957.1.3.el7.x86_64

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (3 by maintainers)

Most upvoted comments

Can only be run under the CLI model. You can use a swoole-based framework. For example: https://github.com/lizhichao/one

Google is your friend 😃, just search swoole chat you will find plenty such as:

https://github.com/Rgss/swoole-chat-demo https://github.com/yaoguais/jegarn

Some of them use rather old version of swoole though, but at least you can get the idea from there.

I changed to PHP-CLI and still the same error as in first post…

it’s impossible, make sure you just run php your_script.php