Reply to Re: [PHP] PHP Memory limit exceeded

Your name:

Reply:


Posted by Ben-Nes Yonatan on 10/02/03 11:07

>> Ben-Nes Yonatan wrote:
>> 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.
>>
>> My server is as follows:
>> 1. PHP 4.3.9
>> 2. DB - Postgresql 7.4
>> 3. Apache 1.3.26
>>
>> 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 save 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...
>
> Do you suspect or that's where the script output ends?
>
> Even between 2nd and 3rd memory_get_usage() call your script's memory
> usage increased rapidly - first the sql query was created, then it was
> assigned to $data. So for a moment the file was in memory twice.
>
> Something similar is with pg_query() - the file was at a moment in $data
> string, then it is copied somewhere in the php_pg module and the memory
> usage tripples.
>
> As a solution you might want to implement (or look for implementation of)
> mysql's load_file() function.
>

Hi Marek and Richard thanks for answering,

First about the memory consumption i knew what u say though wasnt sure 100%
how its working (im self learned so this part wasnt known/clear to me :)),
because of that the option of 16MB to the memory limit seemed logical to me.
At the other hand i did find some huge mistake at my side... only the
download of the file require 28MB (god knows why! but i wont start to bother
u folks about it now) the upload need 16MB so clearly u were correct but im
sorry to admit that i didnt understand y its getting tripled... after all
the result $res is a result of an INSERT not a SELECT therfore it doesnt
return all the data but just an identification if the action went succesful
or not... or maybe im wrong here also?
About the mysql's function... well its mysql and im using postgresql... i
tried to search for something that could help uploading files data to the
server but didnt find anything useful.

I think that i will go on the solution of Richard and just upload the files
to the file system though i dont really like this solution cause ill lose
the integrity of the database.... but then again apprantly i dont really
have any option do i? :P

Thanks again for helping me out,
Ben-Nes Yonatan

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация