Wierd memory problem with Apache / PHP. Related to pg_query ? - Mailing list pgsql-general

From Michael Ben-Nes
Subject Wierd memory problem with Apache / PHP. Related to pg_query ?
Date
Msg-id 42006C10.9020901@canaan.co.il
Whole thread Raw
Responses Re: Wierd memory problem with Apache / PHP. Related to  (Jeff Davis <jdavis-pgsql@empires.org>)
List pgsql-general
Hi all,

I got a problem with uploading files which encounter the memory limit
when their size is not even close to the memory limit itself, let me
explain.

Here is my code that i made for testing the problem (along the code i
echoed the function memory_get_usage() to know how much memory was
allocated already for the script):

$imagefile    =    $_FILES['imagefile']; // recieve the file
echo memory_get_usage().'<br />';    // 118592 memory bytes allocated

$data = pg_escape_bytea(`cat $imagefile[tmp_name]`);
echo memory_get_usage().'<br />';    // 5570280 memory bytes allocated

$data = "INSERT INTO test_files (bin_data, filename, filesize, filetype)
    VALUES ('$data', '$imagefile[name]', '$imagefile[size]',
'$imagefile[type]')";   // creating the sql for the insert, i called the
received value also $data cause i dont want to keep the previous $data
(after all we want to our precious memory no? :))
echo memory_get_usage().'<br />';    // 5570400 memory bytes allocated
{changed from b4 only alittle}

if ( !$res = pg_query ($this->conn, $data) )  // try to insert the sql
string
    return 'error';
else
    return 'gr8';
echo memory_get_usage().'<br />';    // 5570648 memory bytes allocated
{again changed only alittle}


Now as far as i see the script needed about 5.5MB of memory to upload a
file of 4.7MB but thats what so weird here... i receive the memory limit
error even if the php.ini "memory_limit" is set to 16MB! {twice of the
default of 8MB!}  at 32MB it works fine... but thats way too much..
I suspect that the problem is connected to the pg_query function itself
but i didnt find what made it exactly...

Any ideas, knowledge or even just solutions ;) will be extremly helpful.

Thanks in advance,
Ben-Nes Yonatan


pgsql-general by date:

Previous
From: Thomas F.O'Connell
Date:
Subject: Re: PL/PgSQL, Inheritance, Locks, and Deadlocks
Next
From: "Burak B&B"
Date:
Subject: delphi -> postgresql database connect ???