Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ShinJii89 opened this issue Dec 18, 2018 · 22 comments
Closed

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

ShinJii89 opened this issue Dec 18, 2018 · 22 comments
Labels

Comments

@ShinJii89
Copy link

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: [email protected]]
    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

@ShinJii89
Copy link
Author

It's also breaking my website I don't know why? I have now frequently error 500... (not in this script, on my whole server)... it's because extension=swoole.so in php.ini ... I'm sure it's because of that.

@ShinJii89
Copy link
Author

Deleted extension=swoole.so and my server is working without error 500... -.- how to get this all working? with php-fpm and nginx as reverse proxy....

@ShinJii89
Copy link
Author

I hope you gonna help me because I see that your extension is perfect for what I need (couple thousands people online in real-time chat)

@ShinJii89
Copy link
Author

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

@twose
Copy link
Member

twose commented Dec 19, 2018

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

@twose twose added the invalid label Dec 19, 2018
@ShinJii89
Copy link
Author

But why I have to do this in console? I want to make it work in browser...

@ShinJii89
Copy link
Author

Ok I ran it in console - it works... so how to get this work in browser? :)

@yellow1912
Copy link

Swoole is not meant to work in browser, it is a cli based tool for long running tasks, and browser tasks are meant to be short lived tasks.

I think you mentioned about chat app, the idea of swoole is that it can run as a script cli which your users connect to from the browsers.

@ShinJii89
Copy link
Author

So how to get this work if my clients have my script in separate domain and dir (on my server) ?... I thought I can do this like that :/

@yellow1912
Copy link

I don't quite get what you mean, there is not enough information to answer your question. There are a few swoole projects using swoole to power chats, I think you can look into those to get the idea how things work.

@ShinJii89
Copy link
Author

Have you some links?

@yellow1912
Copy link

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.

@lizhichao
Copy link
Contributor

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

@ShinJii89
Copy link
Author

P.S. If I have for example 100 clients - they have 100 scripts with chat... so I wanted to get this work by websockets because php + ajax is shit in performance for my server :P and I thought I can run swoole in php in browser :D

@yellow1912
Copy link

Honestly I think you lack the basic understanding of how Chat programs work, so it would be best for you to start from there first.

Also PHP never ever runs in browsers (at least till now), they always run on server, where CLI mode or not. Your clients from the server open websockets that connect to PHP to do the chat, that's it. You can even do that without swoole. Using swoole you are able to serve more users concurrently and that's the power of swoole.

@ShinJii89
Copy link
Author

Ok maybe I get it... but tell me now why my website (without code from swoole like above) has error 500 every X clicks? If I have turned on extension=swoole.so in php.ini ...
It has to be in Docker if I have websites (nginx etc.) using the same php as swoole? or what...

@yellow1912
Copy link

Since you can enable swoole for cli only, perhaps that's what you should, just enable swoole in cli extension and no where else. It's not meant to run in other modes.

@ShinJii89
Copy link
Author

Ok I understand - thanks guys! :)
Last question - swoole is faster than socket.io ?

@lizhichao
Copy link
Contributor

yes

@ShinJii89
Copy link
Author

I have another question - I think I know how this is working but.... what if I have this 100 separate chats on my server? I guess I should do something like create unique "channel" for every chat? but how? is this possible with swoole?

@yellow1912
Copy link

You seriously need to start reading the documents :). But basically yes, something like this:

https://www.swoole.co.uk/docs/modules/swoole-websocket-server

As for php vs node, i dont think 100 users make any difference, we are talking about hundreds of thousands here. In the end it depends on the language you are more comfortable with.

Read the documents, read the examples, and start from there.

@ShinJii89
Copy link
Author

I didn't tell it's 100 users - it's 100 clients with 100 chats where for every chat can be unlimited people :D but nevermind, thanks for answers :) I now get it... finally :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants