Coroutine\MySQL [编辑本页]

启用协程MySQL客户端

  • 需要在编译swoole时增加--enable-coroutine来开启此功能。

使用示例

$swoole_mysql = new Swoole\Coroutine\MySQL();
$swoole_mysql->connect([
    'host' => '127.0.0.1',
    'port' => 3306,
    'user' => 'user',
    'password' => 'pass',
    'database' => 'test',
]);
$res = $swoole_mysql->query('select sleep(1)');

defer特性

请参考并发Client一节。


  • reluctance_virus

    端口呢, 没有端口啊

  • 弦霄

    'port' => '3306'

  • 挖坑人

    ERROR zm_deactivate_swoole (ERROR 503): Fatal error: Maximum function nesting level of '256' reached, aborting! in index.php on line 3.

  • 张良晖

    没有语言层面的coroutine的基本语义,在connect,query函数内部隐藏了事件循环,那连接池也只能在swoole里实现吧。PHP层面还是没法实现连接池,连接池满了,申请连接的操作不能阻塞,又没法实现轮询。没有连接池,异步的优势又被mysql的并发能力限制住了

  • 泷涯

    去掉xdebug

  • copy

    PHP Warning: Swoole\Coroutine\MySQL::query(): mysql client is waiting response, cannot send new sql query.不能连续执行两个查询?文档要是再清楚点就好了,简直不知道从何下手解决这个问题

  • copy

    问题解决 每次执行下$ws->mysql->recv();就可以了

  • 谁爱这不息的变幻

    zm_deactivate_swoole (ERROR 503): Fatal error: Maximum function nesting level of '256' reached, aborting! in /Users/gaomingjun/Developer/Workspace/zhuoyicp/lumen/vendor/laravel/lumen-framework/src/Concerns/RegistersExceptionHandlers.php on line 58. [2017-04-28 11:39:35 $78402.0] WARNING swManager_check_exit_status: worker#3 abnormal exit, status=255, signal=0