php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64511 Strange memory allocation error message spamming
Submitted: 2013-03-25 14:09 UTC Modified: 2014-10-21 04:03 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:5 of 5 (100.0%)
Same Version:1 (20.0%)
Same OS:1 (20.0%)
From: psiek at mscgva dot ch Assigned:
Status: Closed Package: PDO DBlib
PHP Version: 5.4.13 OS: ubuntu 12.10
Private report: No CVE-ID: None
 [2013-03-25 14:09 UTC] psiek at mscgva dot ch
Description:
------------
Hi,

Each time I use dblib + freetds (read or write) I got following messages :


[Mon Mar 25 08:53:55 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 140429927214120 bytes) in Unknown on line 0, referer: http://blahblah

All seems to work, excepted the weird message that fill my logs.

I tryed with multiple versions of php (from 5.4.0 up to 5.4.11) on three different servers, they all give the same message.

Regards,

Expected result:
----------------
No error message in error/php log

Actual result:
--------------
[Mon Mar 25 08:53:55 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 140429927214120 bytes) in Unknown on line 0, referer: http://blahblah


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-26 16:31 UTC] laruence@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2013-03-26 16:31 UTC] laruence@php.net
-Status: Open +Status: Feedback
 [2013-03-27 11:06 UTC] psiek at mscgva dot ch
Hi,

Thanks for your reply.
Here is a sample code that reproduce the error. Please note that sometimes this code not generate the error, and I can't find why. When you reload the page, it mostly generated but a few time not.

<?php
$connection = new PDO('dblib:dbname=xxx;host=yyy;', 'zxzxzx', 'zxzxzx');
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$query = $connection->query("xxx.dbo.zzzzz @ServerName = NULL, @ProcessName = NULL, @LayoutID = NULL");

$RecordsetFields = array();

do {
       $rowset = $query->fetchAll(PDO::FETCH_ASSOC);
       if ($rowset)
       {
             $RecordsetFields[] = $rowset;
       }
} while ($query->nextRowset());

print_r($RecordsetFields);


The query is working perfectly, excepted the message in error.log.
This is anoyong because we are monitoring errors in real time and this is generating 99% of false positives.

Once again, thanks for your help.

Regards,
 [2013-07-31 01:33 UTC] yohgaki@php.net
[Mon Mar 25 08:53:55 2013] [error] [client x.x.x.x] PHP Fatal error:  Allowed 
memory size of 536870912 bytes exhausted (tried to allocate 140429927214120 
bytes) in Unknown on line 0, referer:

This log indicates that you have been exhausted available memory. (512MB)

When you get query result from your db server, records are stored in memory 
which is not managed by PHP.

If you do

do {
       $rowset = $query->fetchAll(PDO::FETCH_ASSOC);
       if ($rowset)
       {
             $RecordsetFields[] = $rowset;
       }
} while ($query->nextRowset());

Then results are stored in PHP managed memory. I wander why your script works(?) 
even with the memory exhaustion error.

Are you sure that query result fit in your PHP managed memory?
How many records are there? and what the size of each record?

Could you use memory_get_usage() 
http://jp2.php.net/manual/en/function.memory-get-usage.php
in the "do" loop to see memory usage of your script and report the result back?
 [2013-07-31 14:30 UTC] psiek at mscgva dot ch
-Status: Feedback +Status: Open
 [2013-07-31 14:30 UTC] psiek at mscgva dot ch
Hi,

I just added memory_get_usage and memory_get_peak_usage to my script and here is 
the result:

[31-Jul-2013 16:20:56 Europe/Zurich] Script start
[31-Jul-2013 16:20:56 Europe/Zurich] Memory Get Usage: 524288
[31-Jul-2013 16:20:56 Europe/Zurich] Memory Peak Usage: 524288
[31-Jul-2013 16:20:56 Europe/Zurich] Script end
[31-Jul-2013 16:20:56 Europe/Zurich] PHP Fatal error:  Allowed memory size of 
268435456 bytes exhausted (tried to allocate 140188914343656 bytes) in Unknown 
on 
line 0

The problem comes after script execution. Perhaps there is a problem with 
freeing object in memory?

Any idea?
 [2013-11-20 21:08 UTC] gordon dot stratton at gmail dot com
We experienced this problem on PHP 5.4.4, but it was fixed by upgrading to 5.4.21.
 [2013-11-22 07:29 UTC] psiek at mscgva dot ch
Good morning,

We have tested with 5.4.21 and that does not the trick, we still have memory allocation messages.

Regards,
 [2014-04-08 13:54 UTC] d dot vergini at gameprog dot it
same problem here with php 5.4.4-14! false positive, and the query is executed correctly...
please note that "tried to allocate 140429927214120 bytes" is something like 127,5 terabytes... usually bytes exhausted errors try to allocate much smaller memory this is weird...
 [2014-04-26 10:13 UTC] kaido at tradenet dot ee
it's most probably caused by https://bugs.php.net/bug.php?id=67130
 [2014-05-12 13:09 UTC] d dot vergini at gameprog dot it
Solved for me with latest Debian updates, probably was a bug in a PHP extension...
 [2014-05-12 13:53 UTC] psiek at mscgva dot ch
Thanks for the report, which version are you using so ?
 [2014-05-12 14:01 UTC] d dot vergini at gameprog dot it
PHP Version 5.4.4-14+deb7u9
 [2014-05-12 14:09 UTC] psiek at mscgva dot ch
So ad, I'm using 5.4.21.

Thanks anyway.
 [2014-09-09 06:30 UTC] isulic at hotmail dot com
I have same problem :(

PHP 5.5.9-1ubuntu4.3 (cli) (built: Jul  7 2014 16:36:58)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
 [2014-10-02 02:15 UTC] michael at alphageek dot com dot au
I'm getting the same result in my log files for a wordpress site, but I haven't yet determined what statement is causing it.

Here's my PHP info:

PHP 5.5.9-1ubuntu4.4 (cli) (built: Sep  4 2014 06:56:34)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
 [2014-10-21 04:03 UTC] ssufficool@php.net
-Package: MSSQL related +Package: PDO DBlib
 [2014-10-21 04:03 UTC] ssufficool@php.net
$rowset = $query->fetchAll(PDO::FETCH_ASSOC);

This will cache the entire recordset in memory. The pdo dblib driver was updated way back to specifcally allow iteration through a very large recordset (e.g. while($row=$query->fetch()) {}  ) without memory exhaustion, However by calling fetchAll() there is no optimization that can be done.

How many rows with how many bytes each are you fetching from the server? Are there varbinary, text or image fields involved? Those can be quite large.
 [2014-10-23 03:15 UTC] ssufficool@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=83144a72817775f793407d23f2701e9cdabb36cc
Log: Fixed bug #64511 - pdo_dblib segfaults or leaks on nextRowset()
 [2014-10-23 03:15 UTC] ssufficool@php.net
-Status: Open +Status: Closed
 [2014-10-24 20:29 UTC] ab@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=83144a72817775f793407d23f2701e9cdabb36cc
Log: Fixed bug #64511 - pdo_dblib segfaults or leaks on nextRowset()
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of ssufficool
Revision: http://git.php.net/?p=php-src.git;a=commit;h=83144a72817775f793407d23f2701e9cdabb36cc
Log: Fixed bug #64511 - pdo_dblib segfaults or leaks on nextRowset()
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 18:01:30 2024 UTC