php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45797 PDO closes connection too early when combined with pcntl_fork()
Submitted: 2008-08-12 11:46 UTC Modified: 2008-08-12 13:30 UTC
From: jketterl at chipxonio dot de Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.2.6 OS: linux (debian)
Private report: No CVE-ID: None
 [2008-08-12 11:46 UTC] jketterl at chipxonio dot de
Description:
------------
When forking a php skript using pcntl_fork, the PDO connections to a MySQL server are lost as soon as one of the processes exits (parent or child, which ever exits first) and the remaining process can't continue to execute queries (or, even worse, is interrupted during an active query).

the code to reproduce is a CLI script as the application i'm working on is one too. you will need to replace username & password. also, I had to change the file extension in order to make it downloadable.

Reproduce code:
---------------
http://www.djmacgyver.net/files/test2.php.txt

Expected result:
----------------
before fork
records returned: 1
child
records returned: 1
parent
records returned: 1
after fork
records returned: 1
end

Actual result:
--------------
before fork
records returned: 1
child
records returned: 1
parent
records returned: 1
after fork
SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
#0 /home/jketterl/public_html/me/application/import/test2.php(5): PDO->query('select * from p...')
#1 /home/jketterl/public_html/me/application/import/test2.php(41): doQuery(Object(PDO))
#2 {main}
end


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-12 13:30 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's due to the architecture of PHP, you should use different connections in different processes else you get all different kinds of random results, and connecting to a MySQL daemon is a quite cheap operation.
 [2012-01-18 17:29 UTC] xxorax at gmail dot com
However, I think the problem is not to use differents connections in differents 
processes, the problem is to maintain the connection in the parent process, 
because there is no solution to keep a mysql connection in a parent after a child 
closing.

And I am sorry that php does not seem to become a little bit multi-process, in 
default to be multi-threaded...
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 03:01:32 2024 UTC