Re: oncurrence problem with PEAR:MDB2 + msqli driver in forked CLI environment

Matijn Woudt <[email protected]>
Newsgroups gmane.comp.php.database
Message-ID <CAC_gtuOp_MbPivyDweDf+yfhJ-pHRKWGw-3kn9Shni0iU8Zdvw@mail.gmail.com>
On Thu, Jul 4, 2013 at 6:09 PM, Toni Moreno <[email protected]> wrote:

> Hi.
>
> I have a found a very strange and big "concurrence" problem after develop a
> CLI tool which  parallelizes  data processing  by using "pcntrl_fork", ( If
> we run the same executions sequentially the result is correct)
>
> The trouble appears when some of the child processes die while trying to
> access to DB , after child dies, parent process always get status  code of
> 1 or 255..
>
> We can reproduce problem but error messages are not the same always ( I
> attach 3 error log examples)
>
> It seems like a previously stablished connection exists to the bd before
> forking and child processes are working all over it.
>
> Anybody can say me  how can I force child processes to make their own new
> connections  to de BBDD ?
>
>
> Lots of Thanks!!
>
>
First of all, PHP is probably not the right language to do data processing,
but that's up to you.
Second, pcntl_fork is pretty experimental stuff, it's not very stable.

Now to answer your question, it's hard to say without seeing the code, but
I would suspect you only create the database connection once, and use it
from all forks.
The correct way is to create 1 connection per thread, so the threads will
not interfere with each other.

Hope this helps, if not, please show us a small example that demonstrates
the problem.

Regards,

Matijn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.