1

我在 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]

该代码在带有 XAMPP 和 PHP 5.3.8 的 Windows 上工作,唯一的另一个区别是我的 Debian 安装了 MySQLnd,而本地没有。PDO 报告其活动驱动程序为mysql,但跟踪日志表明它正在使用本机驱动程序。

一些谷歌搜索表明本机驱动程序需要在查询之间清除结果,但是,我非常怀疑这种情况,因为(a)apache 在第一次查询时崩溃,在有任何结果之前,并且(b)我尝试使用 clearCursor 清除它们并获取循环。我还尝试unset在准备声明之前对其进行修改。

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

4

1 回答 1

0

在阅读了这篇精彩的问答之后,我注意到 PDO 连接由原始开发人员(在项目中但不活动)设置为持久连接。更改array(PDO::ATTR_PERSISTENT => true,array(PDO::ATTR_PERSISTENT => false,解决问题。

于 2013-07-04T14:18:32.023 回答