Mombu the Php Forum

Go Back   Mombu the Php Forum > Php > PDOStatement execute memory issue?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 19th October 00:59
carlton.whitehead
External User
 
Posts: 1
Default PDOStatement execute memory issue?



Hi everyone,

I'm working on a script that downloads archived fax images (TIFFs and PDFs) from a MS SQL Server using the PDO ODBC driver. I get the below error regardless of which fax I try to get from the database. Each fax is a different size, and both of the memory allocation numbers are always the same:

Fatal error: Out of memory (allocated 262144) (tried to allocate 4294967295 bytes) in C:\Inetpub\wwwroot\FMarchive\library\faxInbound.ph p on line 81

The above error happened when querying a fax with a size of 17723 bytes. According to my phpinfo(); page, the memory_limit is 128MB.

My machine has the below specs:
Windows Server 2003 SP2
IIS 6
2GB RAM
Microsoft SQL Server 2005 SP2
PHP 5.2.4

Here is the excerpt from my code:

public function downloadFax($id, $attid, $attsize)
{
try
{
$stmt = 'SELECT filename, attdata FROM fm_faxin_att WHERE id = :id AND attid = :attid';
$pstmt = $this->db->prepare($stmt);
$pstmt->bindValue(':id', $id);
$pstmt->bindValue(':attid', $attid);
$pstmt->execute(); // this is the Line 81 referenced by the error message
$pstmt->bindColumn('filename', $filename, PDO::PARAM_STR);
$pstmt->bindColumn('attdata', $data, PDO::PARAM_LOB);
$pstmt->fetch(PDO::FETCH_BOUND);

return array('attdata' => $data, 'filename' => $filename);
}
catch (PDOException $e)
{
die($e->getMessage());
}
}

Any ideas?

Regards,
Carlton Whitehead
  Reply With Quote


 


2 19th October 01:00
jeffery
External User
 
Posts: 1
Default PDOStatement execute memory issue?



Ho big are those faxes? 4294967295 bytes = 4GB

have you tried executing that SQL directly into the database? Does it return the right results?

--
Internet Vision Technologies
Level 1, 520 Dorset Road
Croydon
Victoria - 3136
Australia

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQBG+t+H5WXEviRz51oRAg13AKC78sgXGr+V5OG1MvX0te /YAhKeQgCgwK/c
fC1BZWAhjJAkkeLhQP2b3T0=
=CzLY
-----END PGP SIGNATURE-----
  Reply With Quote


 


3 19th October 01:00
cebesius
External User
 
Posts: 1
Default PDOStatement execute memory issue?


No, the faxes aren't 4GB. Most of the faxes are less than 50KB,
although they can be as large as a few MB. 4GB is a ridiculous amount
of memory to try to allocate for this. 4GB is the max that 32bit
versions of Windows can see. Is something causing the memory allocation
to loop until it reaches this maximum value?

When I execute the same SQL in the MS SQL management studio interface, I
get the expected resultset.

When I change the where clause portion in the prepared statement from
"WHERE id = :id AND attid = :attid" to contain "WHERE id =
119085977300014 AND attid = 0" and comment out my bindValue() lines, I
get the exact same memory allocation error in my PHP script.

I have isolated the problem to the query against the attdata column. If
I remove the attdata column from the query, the query executes just
fine. It may be worth noting this is an 'image' type column.

Could this be some bug in the way PHP, PDO, ODBC, and/or MS SQL are
communicating? Maybe 'image' columns aren't being handled correctly?
I'm fairly certain my code is correct. I appreciate all of your comments.

Has anyone even tried querying an 'image' type column out of MS SQL 2005
using PDO ODBC?

Regards,
Carlton Whitehead
  Reply With Quote
4 19th October 01:01
larry
External User
 
Posts: 1
Default PDOStatement execute memory issue?


Try isolating the problem. If you have a literal query through PDO that
fails, in isolation, try the same query using the old-skool odbc routines;
just a trivial test script. If that works but the same test script converted
to minimal PDO fails, you've found a bug. If it fails in both cases, I'd
start blaming something else.

--
Larry Garfield AIM: LOLG42
larry@garfieldtech.com ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
  Reply With Quote
5 19th October 01:01
gmane
External User
 
Posts: 1
Default PDOStatement execute memory issue?


I don't think so as the 4GB value is mentioned in the error message.
Usually when memory is exhausted in a loop it will say "(tried to
allocate 100 bytes)" - e.g. a little amount.

This appears to do it in one chunk.

I wonder if this is trying to allocate memory for the maximum potential
size of your field in the DB? Perhaps read up on PDO/ODBC/MSSQL and how
they treat BLOBs.... (I don't know myself).

Col
  Reply With Quote
6 19th October 01:02
cebesius
External User
 
Posts: 1
Default PDOStatement execute memory issue?


The problem is isolated to PDO ODBC -- old school ODBC works fine.
Below are my test cases.

Plain old ODBC:

<?php
// lobtestOdbc.php
$res = odbc_connect('fmarchive_mssql', 'change', 'me');
if (!$res) { die ('failed to connect'); }

$stp = 'SELECT attdata FROM fm_faxin_att WHERE id = 119085913400004 AND
attid = 0'; // statement to prepare
$ps = odbc_prepare($res, $stp);
if (!$res) { die ('failed to prepare statement'); }

$execResult = odbc_execute($ps);
echo var_export($execResult, true);

?>

The output from the plain old ODBC test case is: true
(indicating that odbc_execute succeeded, see
http://www.php.net/manual/en/function.odbc-execute.php).

Next up, PDO ODBC:

<?php
// lobtestPdoOdbc.php
try
{
$db = new PDO('odbc:fmarchive_mssql', 'change', 'me');

$stp = 'SELECT attdata FROM fm_faxin_att WHERE id = 119085913400004
AND attid = 0'; // statement to prepare
$ps = $db->prepare($stp);
$execResult = $ps->execute();
var_export($execResult, true);
}
catch (PDOException $e)
{
die($e->getMessage());
}

?>

When running lobtestPdoOdbc.php, I get the same old error:

*Fatal error*: Out of memory (allocated 262144) (tried to allocate
4294967295 bytes) in *C:\Inetpub\wwwroot\FMarchive\lobtestPdoOdbc.php*
on line *9*

I tried removing the try-catch blocks with no change in output (still
gets the exact same Fatal Error) -- not like that would be an acceptable
solution anyway.

It appears this is a problem with PDO. I'm starting to really get out
of my league now. How can I go about fixing this?

Regards,
Carlton Whitehead
  Reply With Quote
7 19th October 01:02
carlton.whitehead
External User
 
Posts: 1
Default PDOStatement execute memory issue?


Hi Colin,

The MS documentation says the image type can hold up to 2GB: http://technet.microsoft.com/en-us/l.../ms187993.aspx

It appears someone beat me to filing a bug report about this: http://bugs.php.net/bug.php?id=42765

I guess that's that for now until this gets fixed.

Regards,
Carlton Whitehead

----- Original Message -----
From: "Colin Guthrie" <gmane@colin.guthr.ie>
To: php-general@lists.php.net
Sent: Thursday, September 27, 2007 4:04:53 AM (GMT-0500) America/New_York
Subject: [php] Re: PDOStatement execute memory issue?

I don't think so as the 4GB value is mentioned in the error message.
Usually when memory is exhausted in a loop it will say "(tried to
allocate 100 bytes)" - e.g. a little amount.

This appears to do it in one chunk.

I wonder if this is trying to allocate memory for the maximum potential
size of your field in the DB? Perhaps read up on PDO/ODBC/MSSQL and how
they treat BLOBs.... (I don't know myself).

Col

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
  Reply With Quote
Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Php 5 forum, Apache forum, Iis forum, Functions forum, Classes forum, Librarys forum, Bugs forum, Postgres forum, Mysql forum, Paradox forum, Ms sql forum, Configurations forum, Php.ini forum, Problems forum, Scripting forum, Css forum, General forums, Off-topic talk, Links, Extra forums, Php


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666