|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-03-16 09:16 UTC] julien at palard dot fr
Description:
------------
PDO Segfaults or hangs when a statement is executed with both ATTR_PERSISTENT =>
TRUE and ATTR_EMULATE_PREPARES => FALSE
The exact bug is actually :
*** glibc detected *** /usr/local/php-5.4.0/bin/php: free(): invalid pointer:
0x00007ff976ee84c8 ***
But from my tests yesterday I have seen a segfault and a double free, that I
can't reproduce today, only the invalid pointer.
Playing with PERSISTENT and EMULATE_PREPARE with the given test script give :
| ATTR_PERSISENT | ATTR_EMULATE_PREPARES | WORKS |
| FALSE | FALSE | YES |
| FALSE | TRUE | YES |
| TRUE | FALSE | free() invalid pointer |
| TRUE | TRUE | YES |
Configure command :
./configure' '--enable-fpm' '--prefix=/usr/local/php-5.4.0' '--enable-mbstring'
'--enable-gd-native-ttf' '--enable-zip' '--with-mcrypt' '--with-openssl' '--
with-gd' '--with-jpeg-dir=/usr/lib' '--with-freetype-dir' '--with-curl' '--with-
pcre-regex' '--with-gettext' '--without-sqlite' '--without-sqlite3' '--with-pdo-
mysql=mysqlnd' '--disable-rpath' '--disable-debug' '--disable-fileinfo' '--
without-pdo-sqlite' '--disable-phar' '--disable-posix' '--disable-tokenizer' '--
disable-xmlreader' '--disable-xmlwriter' '--without-pear'
Same bug reproduced in php 5.3.8 and php 5.3.10
Test script:
---------------
<?php
$options = array(PDO::ATTR_PERSISTENT => TRUE,
PDO::ATTR_EMULATE_PREPARES => FALSE);
$pdo = new PDO('mysql:host=sql;dbname=??;charset=utf8',
'??', '??', $options);
$statement = $pdo->prepare("SELECT count(*) from a_table");
$statement->execute();
foreach ($statement as $line)
var_dump($line);
Expected result:
----------------
I expect PHP not to segfault
Actual result:
--------------
*** glibc detected *** /usr/local/php-5.4.0/bin/php: free(): invalid pointer:
0x00007ff976ee84c8 ***
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 15:00:02 2025 UTC |
Perhaps this is a slightly different problem with the same symptoms. The problem I see is using ATTR_PERSISTENT => true with ATTR_EMULATE_PREPARES => false with a low wait_timeout on the server causes "MySQL server has gone away" issues. To replicate this try the following. Configure your MySQL with a wait_timeout of 2 seconds. Then run the following. function create_connection(){ $options = array(PDO::ATTR_PERSISTENT => TRUE,PDO::ATTR_EMULATE_PREPARES => FALSE); return new PDO('mysql:host=127.0.0.1;dbname=trafficadbar;charset=utf8', 'root', 'wnn99BCc', $options); } $pdo = create_connection(); sleep(5); $pdo1 = create_connection(); $statement = $pdo1->prepare("SELECT count(*) from users"); $statement->execute(); foreach ($statement as $line) var_dump($line);Don, That's interesting. Have you tried my code with settings your MySQL timeout less than than the sleep? function create_connection(){ $options = array(PDO::ATTR_PERSISTENT => TRUE,PDO::ATTR_EMULATE_PREPARES => FALSE); return new PDO('mysql:host=127.0.0.1;dbname=trafficadbar;charset=utf8', 'root', 'wnn99BCc', $options); } $pdo = create_connection(); sleep(5); $pdo1 = create_connection(); $statement = $pdo1->prepare("SELECT count(*) from users"); $statement->execute(); foreach ($statement as $line) var_dump($line);I ran all the various tests here, and could not recreate any issues. I've even forcefully restarted MySQL in the middle of a script running to see what would happen, and things went fine. I'm using: PHP 5.6.9-1 (cli) (built: May 22 2015 10:48:57) Copyright (c) 1997-2015 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies with XCache v3.2.0, Copyright (c) 2005-2014, by mOo with Suhosin v0.9.37.1, Copyright (c) 2007-2014, by SektionEins GmbH with XCache Optimizer v3.2.0, Copyright (c) 2005-2014, by mOo with XCache Cacher v3.2.0, Copyright (c) 2005-2014, by mOo with XCache Coverager v3.2.0, Copyright (c) 2005-2014, by mOo With the mysqlnd extension and mysql Ver 14.14 Distrib 5.5.43, for debian-linux-gnu (x86_64) using readline 6.3. Aside from the original reporter, no one specified which MySQL extension they were using, so it's possible certain bugs exist in certain versions with a certain extension, but it's unclear which exactly.