pinguo / php-msf

PHP微服务框架即Micro Service Framework For PHP
GNU General Public License v2.0
1.75k stars 317 forks source link

要实现在启动时自动加载数据表结构。 #104

Closed wuchuguang closed 6 years ago

wuchuguang commented 6 years ago
onWorkerStart
        $poolName = 'master';
        $instnce = getInstance();
        $activePoolName = $poolName;
        $poolName       = MysqlAsynPool::ASYN_NAME . $poolName;
        $pool = $instnce->getAsynPool($poolName);
        if (!$pool) {
            $pool = new MysqlAsynPool($instnce->config, $activePoolName);
            getInstance()->addAsynPool($poolName, $pool, true);
        }
        $tables = yield $pool->go(null, 'show create table config_channel');
        print_r($tables);

没有打印print_r($tables);

viaweb3 commented 6 years ago

onWorkerStart的时候,协程还没有初始化好。

wuchuguang commented 6 years ago

yied在框架的基础上,好像都不能使用。onWorkerStart,等等。那有没有同步mysql的?

wuchuguang commented 6 years ago

现在pool->go();拿到的select数据,数据类型全是string. 但事实表有某些int/bigint类型的。我要自已转了,不转的话,传给前端无法用===,只能用== 所以想在服务器启动时,一次性把表结构拿到手。后面数据做转换。

viaweb3 commented 6 years ago

可以使用同步的方法,就是原始的 Pdo。

wuchuguang commented 6 years ago

msf有现成pdo封装吗?

viaweb3 commented 6 years ago

没有原始的Pdo封装,我建议在Config进程或者Timer进程里实现初始化数据表结构的逻辑,具体使用方法可以参考文档或者demo。