pcntl_fork and the MySQL connection is gone(pcntl_fork 和 MySQL 连接消失了)
问题描述
我有一个 foreach 循环,它在其中分叉.在进程 fork 之后,它访问数据库.我收到一个错误:
I have a foreach loop that forks within it. After the process forks, it accesses the database. I get an error:
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
问题是,我正在分叉之后连接到数据库.
The thing is, I'm connecting to the database after I've forked.
我的问题:为什么会发生这种情况?
My question: Why would this be happening?
如果发生这种情况,我是否真的在分叉之前访问了数据库??孩子会继承数据库连接吗?
If this happens, am I actually accessing the database before forking? Will the child inherit DB connections?
(注意:我可以发布代码,但它相当大,因为它都在类中,这可能是导致我在访问数据库时感到困惑的原因.您应该知道的另一件事是我正在使用 ZF.)
(note: I can post code, but it's rather large as it's all in classes, which could be what is causing my confusion of when I'm accessing the DB. Another thing you should know is I'm using ZF.)
推荐答案
(comment --> answer per poster's request)
(comment --> answer per poster's request)
阅读更多内容我看到分叉的孩子确实继承了他们父母的数据库连接,这是一个已知问题:http://php.net/manual/en/function.pcntl-fork.php#70721
Reading more into it I see forked children do inherit their parent's db connection, and it is a known problem: http://php.net/manual/en/function.pcntl-fork.php#70721
这篇关于pcntl_fork 和 MySQL 连接消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:pcntl_fork 和 MySQL 连接消失了
基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
