From:             alan dot blotz at students dot uni-mainz dot de
Operating system: Debian Lenny
PHP version:      5.2.6
PHP Bug Type:     MySQL related
Bug description:  pcntl_fork() with MySQL queries

Description:
------------
Already a long time ago the bug http://bugs.php.net/bug.php?id=38228 was
active, but I experienced some problems with the pcntl_fork() function
today. I already fixed the problem with multiple children connecting to the
MySQL server by using mysql_connect(..., true) or mysql_pconnect() (the
latter I'm using right now). My problem is, that with any of these methods
I'm partly getting wrong results to queries (see code). This really NOT
happening always, just sometimes when you don't expect it.

I can't post the original code due to copyrights, but the example below
should give you an idea of what is happening. I'm working with multiple
children in my application (executed as CLI), at least five at a time. Is
it perhaps a memory problem of PHP and / or MySQL?


Alan

Reproduce code:
---------------
// Queries for five children
for ($i = 0; $i < 5; $i++) {
        
        // If I am the child
        if (!pcntl_fork()) {
                
                switch ($i) {
                        
                        case 0:
                                $sql = 'SELECT a, b FROM t';
                                break;
                        case 1:
                                $sql = 'SELECT c FROM s';
                                break;
                        case 2:
                                $sql = 'SELECT x FROM s';
                                break;
                        case 3:
                                $sql = 'SELECT a, b, d FROM t';
                                break;
                        case 4:
                                $sql = 'SELECT d FROM t';
                                break;
                }
                
                $result = mysql_query($sql);
                // Get the result from DB with mysql_fetch_array() for example
        }
}

Expected result:
----------------
Result of columns a and b from table t in first child
Result of column c from table s in second child
Result of column x from table s in third child
Result of columns a, b and d from table t in fourth child
Result of column d from table t in fifth child

Actual result:
--------------
For example (some worst case):

Nothing in first child
Result of column x from table s in second child
Result of column c from table s in third child
Result of columns a and b from table t in fourth child
Result of column d from table t in fifth child

-- 
Edit bug report at http://bugs.php.net/?id=45590&edit=1
-- 
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=45590&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=45590&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=45590&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=45590&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=45590&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=45590&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=45590&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=45590&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=45590&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=45590&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=45590&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=45590&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=45590&r=globals
PHP 4 support discontinued:   http://bugs.php.net/fix.php?id=45590&r=php4
Daylight Savings:             http://bugs.php.net/fix.php?id=45590&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=45590&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=45590&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=45590&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=45590&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=45590&r=mysqlcfg

  • #45590 [NEW]: pcntl_fork()... alan dot blotz at students dot uni-mainz dot de

Reply via email to