php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55003 PDO prepare() ignores MYSQL_ATTR_USE_BUFFERED_QUERY
Submitted: 2011-06-06 20:15 UTC Modified: 2013-02-18 00:34 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: jamesvl+php at gmail dot com Assigned:
Status: No Feedback Package: PDO related
PHP Version: 5.3.6 OS: all
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jamesvl+php at gmail dot com
New email:
PHP Version: OS:

 

 [2011-06-06 20:15 UTC] jamesvl+php at gmail dot com
Description:
------------
Steps to reproduce:

Set up a database so a query can return ~ 10,000 rows - enough to bump memory usage to noticeable levels.

Use PDO to prepare a query where you explicitly disable buffered queries: PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false. The PHP docs give an example of how to do this at http://www.php.net/manual/en/ref.pdo-mysql.php.

Execute that statement.

Use "memory_get_peak_usage()" to watch PHP memory usage for the script before and after the call to pdoStmt->execute().

Notes:

Settings PDO::MYSQL_ATTR_USE_BUFFERED_QUERY to false when creating the PDO object *does* work as expected. (i.e. query buffering will be turned off or on; default is on if not specified)

However, the PHP documentation makes it appear that an individual prepared statement should be able to change or override this settings for an individual query, which is not the case.

PHP version tested: PHP 5.3.6 using mysqlnd, Win32 and Linux custom compile.
Note that testing on PHP 5.2 (i.e. without mysqlnd) is not possible since mysqlib allocates memory outside of the PHP parser, and thus is not tracked by memory_get_peak_usage() and is not limited by php.ini memory_limit settings.

Test script:
---------------
if ($this->db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') {
   $stmt = $this->db->prepare($qry,
      array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false));

   echo "\nmax bytes mem used: " . memory_get_peak_usage() . "\n";
   $stmt->execute();
   echo "max bytes mem used: " . memory_get_peak_usage() . "\n";
}

Expected result:
----------------
Expect to see:

Very little new memory allocated even when returning large result sets.

Memory usage should *not* vary based on the result set size.

ex:
max bytes mem used: 700624
max bytes mem used: 700624

Actual result:
--------------
Actually see:

Memory usage increases directly with the size of the result set returned - PDO is using a buffered query.

ex:
max bytes mem used: 700240
max bytes mem used: 26291600

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-04 09:16 UTC] uw@php.net
Please try using this snapshot:

  http://snaps.php.net/php5.4-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/


 [2012-05-04 09:16 UTC] uw@php.net
-Status: Open +Status: Feedback
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 24 03:01:32 2024 UTC