php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63642 No "out of memory" error during ->fetchAll() from PostgreSQL
Submitted: 2012-11-29 00:25 UTC Modified: 2013-08-21 10:14 UTC
From: amex at bucksvsbytes dot com Assigned: willfitch (profile)
Status: Not a bug Package: PDO related
PHP Version: 5.3.19 OS: Ubuntu
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: amex at bucksvsbytes dot com
New email:
PHP Version: OS:

 

 [2012-11-29 00:25 UTC] amex at bucksvsbytes dot com
Description:
------------
In PHP 5.3.10 and PostgreSQL 9.1, when executing PDOStatement::fetchAll(), if the retrieved data busts the PHP memory limit, the script dies quietly, without throwing an "out of memory" error.

Test script:
---------------
//ini_set('memory_limit','256M');
$dsn=;//appropriate Data Source Name string
$sql=;//any query that returns slightly more data than the PHP memory limit allows (default limit is 128 MB on my server)
$db=new PDO($dsn);
$result=$db->query($sql);
$datarray=$result->fetchAll();//fetch all rows into an array


Expected result:
----------------
When fetchAll() retrieves too much data, the script dies quietly, instead of throwing an "out of memory" error.
When I uncomment the first line, the script runs to completion, thus proving that the quiet death was due to lack of memory.

The problem seems to relate to the postgresql driver, as the same thing happens when I use pg_connect/pg_query/pg_fetch_all instead of PDO to get data from the same query.

This is the only PHP "out of memory" condition I've ever seen where no error is thrown.



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-18 21:17 UTC] willfitch@php.net
Without looking into this too far, have you verified that 
error_reporting/display_errors are set to levels that are sufficient to display or 
record this error?
 [2012-12-18 21:17 UTC] willfitch@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: willfitch
 [2012-12-19 00:09 UTC] amex at bucksvsbytes dot com
Yes, my PHP development system displays every error, warning, and notice on screen.
 [2013-08-21 10:14 UTC] mike@php.net
-Status: Assigned +Status: Not a bug
 [2013-08-21 10:14 UTC] mike@php.net
Cannot reproduce.  This is probably your kernel OOM killer tricking you.

cli -d error_reporting=-1 -d memory_limit=5M -r '$pdo = new 
PDO("pgsql:user=phptest dbname=phptest"); $stm = $pdo->query("select 
repeat(\x27a\x27, 5*1024*1025) as data"); var_dump($stm->fetchAll());'

Fatal error: Allowed memory size of 5242880 bytes exhausted at 
/home/mike/src/php-5.4/ext/pdo/pdo_stmt.c:641 (tried to allocate 5248001 bytes) 
in Command line code on line 1
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 23:01:28 2024 UTC