E
E
ekopach2014-02-19 21:54:29
Zend Framework
ekopach, 2014-02-19 21:54:29

Zend PDO_MYSQL: using with pcntl_fork?

I'm writing a php daemon using pcntl_fork, the MySQL has gone away error keeps popping up. It is clear that after exit(), the connection is destroyed in the child process, but I still can’t find a solution ...
In the usual mysql_connect, there is a new_link parameter that creates a new connection, but a lot has already been written with Zend_Db.
I also thought to use posix_kill(posix_getpid(), SIGTERM) instead of exit - but noticed that then zombie processes are spawned.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vit, 2014-02-19
@fornit1917

The connection to the database must be established after the fork, each process has its own.
Not an expert on Zend, but I think that there you can clearly understand at what point the connection to the database is established. And these actions (leading to the creation of a connection to the database) must be done in each child process separately.
I can also recommend to abandon forks altogether and "daemonize" php using supervisord. In my opinion, a much better and more convenient solution, besides, you will get additional buns out of the box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question