PDO MySQL在语句执行时崩溃了apache

时间:2013-07-04 13:28:49

标签: php mysql pdo apache2 mysqlnd

我在Debian 6上使用PHP 5.4.4和MySQL 5.5.31。我有以下代码:

file_put_contents("dump.log", $check_username); // To ensure the variable is set, which it is
$database->query('SELECT * FROM users WHERE username = :username', array(':username' => $check_username));
die("Query didn't crash");

查询功能在这里:

public function query($query, $bind = null) {
    global $pdo;
    /* Prepare Statment */
    try {
        $this->statement = $this->pdo->prepare($query);
    }
    catch(Exception $e) {
        echo "MySQL Exception -> " . $e->getMessage();
    }
    /* Execute Query */
    return $this->statement->execute($bind); // Crash here
}

此时apache2崩溃并出现以下错误,并且不向客户端返回任何内容:

*** glibc detected *** /usr/sbin/apache2: free(): invalid pointer: 0x00007fb3b61dbbf8 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x76d76)[0x7fb3b3840d76]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x6c)[0x7fb3b3845aac]
/usr/lib/php5/20100525/mysqlnd.so(_mysqlnd_pefree+0x4e)[0x7fb3ac14ac7e]
/usr/lib/php5/20100525/mysqlnd.so(+0x2645f)[0x7fb3ac15e45f]
/usr/lib/php5/20100525/mysqlnd.so(+0x278e0)[0x7fb3ac15f8e0]
/usr/lib/php5/20100525/mysqlnd.so(+0x2614e)[0x7fb3ac15e14e]
/usr/lib/php5/20100525/pdo_mysql.so(+0x4f7f)[0x7fb3a99b0f7f]
/usr/lib/php5/20100525/pdo.so(+0xc39a)[0x7fb3abf2839a]
/usr/lib/apache2/modules/libphp5.so(zend_objects_store_del_ref_by_handle_ex+0x293)[0x7fb3b0818d63]
/usr/lib/apache2/modules/libphp5.so(zend_objects_store_del_ref+0x13)[0x7fb3b0818d83]
/usr/lib/apache2/modules/libphp5.so(_zval_ptr_dtor+0x3a)[0x7fb3b07e312a]
/usr/lib/apache2/modules/libphp5.so(zend_hash_destroy+0x38)[0x7fb3b07ffe88]
/usr/lib/apache2/modules/libphp5.so(zend_object_std_dtor+0x2c)[0x7fb3b0812fbc]
/usr/lib/apache2/modules/libphp5.so(zend_objects_free_object_storage+0x9)[0x7fb3b0813049]
/usr/lib/apache2/modules/libphp5.so(zend_objects_store_free_object_storage+0x87)[0x7fb3b0818897]
/usr/lib/apache2/modules/libphp5.so(+0x35668c)[0x7fb3b07e368c]
/usr/lib/apache2/modules/libphp5.so(+0x3650b5)[0x7fb3b07f20b5]
/usr/lib/apache2/modules/libphp5.so(php_request_shutdown+0x1da)[0x7fb3b0791a3a]
/usr/lib/apache2/modules/libphp5.so(+0x40f35f)[0x7fb3b089c35f]
/usr/sbin/apache2(ap_run_handler+0x70)[0x7fb3b4670ab0]
/usr/sbin/apache2(ap_invoke_handler+0xce)[0x7fb3b467444e]
/usr/sbin/apache2(ap_process_request+0x1c8)[0x7fb3b4682078]
/usr/sbin/apache2(+0x52f28)[0x7fb3b467ef28]
/usr/sbin/apache2(ap_run_process_connection+0x68)[0x7fb3b46786a8]
/usr/sbin/apache2(+0x5b1b7)[0x7fb3b46871b7]
/usr/sbin/apache2(+0x5b4ca)[0x7fb3b46874ca]
/usr/sbin/apache2(ap_mpm_run+0xc24)[0x7fb3b4688154]
/usr/sbin/apache2(main+0xb40)[0x7fb3b465ca90]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xfd)[0x7fb3b37e8ead]
/usr/sbin/apache2(+0x2fa29)[0x7fb3b465ba29]

代码在Windows上使用XAMPP和PHP 5.3.8,唯一的另一个区别是我的Debian安装了MySQLnd,而本地安装没有。 PDO报告其活动驱动程序为mysql,但是tracelog建议它使用本机驱动程序。

一些谷歌搜索建议本机驱动程序要求在查询之间清除结果,但是,我非常怀疑这是因为(a)apache在第一次查询时崩溃,在有任何结果之前和(b)我尝试清除它们同时使用clearCursor和fetch循环。在准备之前,我还尝试过unset语句。

问题:如何修复查询功能以防止服务器崩溃?

1 个答案:

答案 0 :(得分:0)

在阅读this great Q&A之后,我注意到PDO连接被原始开发人员(在项目中但处于非活动状态)设置为持久性。将array(PDO::ATTR_PERSISTENT => true,更改为array(PDO::ATTR_PERSISTENT => false,可解决问题。