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

无法同时使用Swoole\Coroutine\MySQL和Swoole\MySQL #1669

Closed
Yurunsoft opened this issue May 29, 2018 · 5 comments
Closed

无法同时使用Swoole\Coroutine\MySQL和Swoole\MySQL #1669

Yurunsoft opened this issue May 29, 2018 · 5 comments

Comments

@Yurunsoft
Copy link
Member

Yurunsoft commented May 29, 2018

这两个使用顺序不同,报错也不同。。。

代码1

<?php
use \Swoole\Coroutine as co;
co::create(function() {
    $server = [
        'host' => '192.168.0.110',
        'user' => 'root',
        'password' => 'root',
        'database' => 'test',
    ];
    

    $db = new \Swoole\MySQL;
    $db->connect($server, function ($db, $r) {
        var_dump('connect');
    });
    
    $db = new co\MySQL();
    $ret1 = $db->connect($server);
    var_dump($ret1);
});

结果:

string(7) "connect"
PHP Notice:  Undefined property: Swoole\Coroutine\MySQL::$onConnect in Unknown on line 0
PHP Warning:  Invalid callback , no array or string given in Unknown on line 0
PHP Warning:  swoole_event_wait(): swoole_mysql onConnect handler error. in Unknown on line 0
bool(false)

代码2

<?php
use \Swoole\Coroutine as co;
co::create(function() {
    $server = [
        'host' => '192.168.0.110',
        'user' => 'root',
        'password' => 'root',
        'database' => 'test',
    ];
    

    $db = new co\MySQL();
    $ret1 = $db->connect($server);
    var_dump($ret1);

    $db = new \Swoole\MySQL;
    $db->connect($server, function ($db, $r) {
        var_dump('connect');
    });
});

结果:

bool(true)
Segmentation fault (core dumped)
@matyhtf
Copy link
Member

matyhtf commented May 29, 2018

请勿同时使用协程和异步回调两种版本的客户端。由于底层 reactor 的 fdtype 是相同的,会导致协程客户端调用了异步客户端的 Reactor Handler ,必然会出现 crash

@Yurunsoft
Copy link
Member Author

那目前看来有了协程,异步的客户端很鸡肋了

@matyhtf
Copy link
Member

matyhtf commented May 29, 2018

异步回调客户端 可能会在接下来的版本中移除。

@Yurunsoft
Copy link
Member Author

好的,非常感谢

@Frank-JY
Copy link

Frank-JY commented Aug 7, 2020

请问这里代码2的问题如何解决

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

No branches or pull requests

3 participants