swoole-src
swoole-src copied to clipboard
Why is Swoole heartbeat doesn't work and why Coroutine/Mysql connect to 127.0.0.1 if parameter host is localhost?
Hi, I have Swoole 4.2.12 and PHP 7.3
$this->server->set([ 'ssl_cert_file' => '/etc/httpd/conf/ssl.crt/server.crt', 'ssl_key_file' => '/etc/httpd/conf/ssl.key/server.key', 'heartbeat_check_interval' => 1000, 'heartbeat_idle_time' => 6000, 'max_conn' => 100000 ]);
-
function heartbeat seems not working because if people don't write anything on chat it ALWAYS disconnect after 100 seconds... always.... why?
-
I have
$this->db = new Swoole\Coroutine\Mysql(); $smysql = array( 'host' => 'localhost', 'port' => 3306, 'user' => 'xxx', 'password' => 'xxx', 'database' => 'xxx' ); $this->db->connect($smysql);
And there's error 28000 Access denied for user 'xxx'@'127.0.0.1' (using password: YES)
- why it tries connect by 127.0.0.1 if I write host parameter as localhost? if I use just new mysqli()
it connects and works... but I need coroutine...
Ok I added user [email protected] to my mysql and now it connects (so problem number 2 is solved) but.... hmmm.... why I have now error after start my script (before add coroutine there was no error)
Memory protection violation (core dumped)
[it's translated from polish language, I don't know if it's the same in english system] and it exits to shell... wtf? I have memory_limit 16gb in php etc. so where's the problem?
As I said - it was working without coroutine but script is way faster than mysql and if I have for example 15 000 connected clients there's sometimes "mysql has gone away" and I thought I have to add Coroutine... but there's some problem with memory now :///
EDIT: I found that it happens (this error) after $this->db->connect($mysql);
On the contrary, when the heartbeat is turned off then the connection would not be broken. And websocket protocol has its own heartbeat, tcp heartbeat is not required.
because localhost will be resolved to 127.0.0.1. I think mysqli uses unixsocket, not tcp.
I remember many browser don't send ping frame so this heartbeat is required
Any examples for heartbeat (in frontend - yes?) ? Because it's always disconnect me after 100 seconds... - @twose - even if I delete hearbeat from settings
And what about this error with memory (ram) in my second post? It's error with swoole or what? I don't get it.... because I understand if mysql (normal mysqli function) doesn't follow speed of Swoole then I have to use Coroutine, yes? because it speeds up mysql then?
@ShinJii89 websocket client should send ping frame to the server, you can find some examples about it, swoole websocket server would never close the connection if you did not set the heartbeat