pcntl_fork和MySQL连接消失了 [英] pcntl_fork and the MySQL connection is gone

查看:164
本文介绍了pcntl_fork和MySQL连接消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个foreach循环在其中分叉.在进程派生之后,它将访问数据库.我收到错误消息:

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?

如果发生这种情况,我实际上是在 分叉之前访问数据库吗?子级会继承DB连接吗?

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)

深入了解它,我发现分叉的孩子确实继承了其父母的db连接,这是一个已知的问题:

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连接消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆