Bug #75402 [Opn->Csd]: Possible Memory Leak using PDO::CURSOR_SCROLL option
| From: | ab@php.net | Date: | Mon, 30 Jul 2018 16:30:24 +0000 |
| Subject: | Bug #75402 [Opn->Csd]: Possible Memory Leak using PDO::CURSOR_SCROLL option | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-216525@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75402&edit=1
ID: 75402
Updated by: ab@php.net
Reported by: olric86 at gmail dot com
Summary: Possible Memory Leak using PDO::CURSOR_SCROLL option
-Status: Open
+Status: Closed
Type: Bug
Package: PDO PgSQL
Operating System: Windows 10
PHP Version: 7.1.10
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=cc69950b1527b321bf54a9394938d57e8f5a35cc
Log: Fixed bug #75402 Possible Memory Leak using PDO::CURSOR_SCROLL option
Previous Comments:
------------------------------------------------------------------------
[2017-10-17 21:33:31] olric86 at gmail dot com
Description:
------------
Hi,
while migrating a project which was using PDO->MSSQL
(https://docs.microsoft.com/it-it/sql/connect/php/microsoft-php-driver-for-sql-server) to
PDO->PostgreSQL, I found a strange behavior in how memory is retained by PHP when prepared
statements are 'prepared' with the
\PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL
option, at least on Microsoft Windows.
By using the test script attached, it looks like memory used during the result set object retrieval
is never de-allocated, leading to an abnormal memory consumption and ultimately to a httpd.exe crash
on 32 bit systems due to memory allocation limitations.
I'm using a x64 build of PHP 7.1.10 with Apache 2.4.28 on a Windows 10 x64 PRO and I've
also tested the following with PHP 5.4 32 bit and with PHP 7.0 32bit.
The behavior looks to be the same, each time the script is ran the memory used by httpd.exe
increments by almost 800KB and it never get released.
We saw processes keeping up to 1.5Gb of RAM on 32bit OSs.
By simply changing the prepared statement 'prepare' option to:
\PDO::ATTR_CURSOR => \PDO::CURSOR_FWDONLY
memory is allocated and de-allocated correctly.
You can see here:
https://drive.google.com/open?id=0Bx83lRq7kAiKY0ViRFJWMkxBZlE
how quickly memory is being allocated and never released.
Initially I thought it was some kind of caching mechanism of PHP/PDO/PGSQL but memory allocation
seems to be simply increasing with no limit.
This does not happen with the CURSOR_FWDONLY option.
Please find a sample test script below.
Test script:
---------------
SQL Table creation script:
https://drive.google.com/open?id=0Bx83lRq7kAiKSldZNEZ5QXh5R0E
SQL Dummy data insert script:
https://drive.google.com/open?id=0Bx83lRq7kAiKdTJRTERjQzh1NEk
PHP test script:
https://drive.google.com/open?id=0Bx83lRq7kAiKQWt5QTNHdmhPVmc
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75402&edit=1