|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75402 Possible Memory Leak using PDO::CURSOR_SCROLL option
Submitted: 2017-10-17 21:33 UTC Modified: -
From: olric86 at gmail dot com Assigned:
Status: Closed Package: PDO PgSQL
PHP Version: 7.1.10 OS: Windows 10
Private report: No CVE-ID: None
 [2017-10-17 21:33 UTC] olric86 at gmail dot com

while migrating a project which was using PDO->MSSQL ( to PDO->PostgreSQL, I found a strange behavior in how memory is retained by PHP when prepared statements are 'prepared' with the


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:


memory is allocated and de-allocated correctly.

You can see here:

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:

SQL Dummy data insert script:

PHP test script:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-07-30 16:30 UTC]
Automatic comment on behalf of ab
Log: Fixed bug #75402 Possible Memory Leak using PDO::CURSOR_SCROLL option
 [2018-07-30 16:30 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Tue Jun 06 09:03:41 2023 UTC