PDA

View Full Version : script memory


edbr
04-17-2013, 08:03 AM
having a nightmare while trying to intergrate a script. im getting the failure
Fatal error: Allowed memory size of 314572800 bytes exhausted (tried to allocate 35 bytes) in C:\wamp\www\dateline\init.php on line 33

originally it was lower but i have increased memory size in php.inii to a crazy 300 meg but getting same warning, i also tied adding ini_set("memory_limit","300M"); but getting no where.
Any clues anybody??

jmichae3
04-19-2013, 02:22 AM
did you mean php.ini rather than php.inii?

lessee: I am not sure if PHP interprets that memory parameter in terms of IEC units or in terms of SI units (ahh, got it's it's IEC units), so in case it's SI units, try bumping it to 400M(400MiB) - or 700M - for now you are only testing limits - you can change it down later.
I don't know how large the scripts are or how big your data queries are. I have one script that's 75K in size and it consumes 101-104MB.

there is echo memory_get_peak_usage();
so set it really high, insert the above and then you can tune it later. all I did was think: hmm, I wonder if there are any memory functions in there? so I looked in the php .chm manual index and types in memory and came up with this nice function.

only thing you should really trust in is that peak ram usage function. I wouldn't cut it too close though, since there are dynamic things (such as database queries memory usage, forms, etc) when it comes to scripting. and there is no deallocator. just gc (garbage collection).

jmichae3
04-19-2013, 02:35 AM
got the stats from my other file.
Peak Ram Usage: 4079168
filesize: 75336

the first file was also about 75k but used about 104MB.

edbr
04-22-2013, 03:39 AM
thanks, i didnt really want to get beyond that. it is an inherited script fr a chat plugin. i worked around it for now but it is not sure that the project will happen now. i would like to get to the bottom of this. I suspect there is an endless loop causing problems here as it pertains to gathering member names form a db. i will return to it but posted incase there is was a magic bullet that would sort it

thank you for that function i had not heard of that

jmichae3
04-22-2013, 07:00 AM
ahh... this can be usually be traced to
- infinite recursion (a function that calls itself with no limits, can be a tree walking function such as DOM walker that is broken)
- mutual recursion (a function which calls another function which calls the first function, with no limiting factor)
- ginormous (100k-to-1M-row) table queries? i.e. selecting the entire MAXMIND GEOIP IP table because you forgot to include a conditional in the WHERE clause of your SQL

the recursion can be in something object-opriented, such as methods in a class that have not been fully debugged.
if the package is from a 3rd party, report the bug to the author(s) so they can fix it.

if you can provide a patch, even better. usually patches are submitted using either diff or the patch tool I think (still somewhat of a mystery to me, I should ask one of these times when I think about it).

if this thing just consumes all the memory you have got and then crashes or dies at whatever limit, you have a recursion problem most likely.

this is because when you call a function, its parameters and local variables are pushed on the stack. when it calls itself repeatedly, well, you get the picture - the STACK blows up out of proportion and chews up all available memory.

if there were no limit, it would crashdump/coredump/SIGFAULT/etc. this is my guess as to why php has a memory limit on its scripts - for security reasons. you can't have a bad script causing a bunch of crashdumps that take forever on a big-memory server.

but I digress.

edbr
04-22-2013, 07:54 AM
yes indeed i suspect it is an included class but suspect it will be a lost cause, in he mean time i visited the developers site and it is very very slow to load and i am not convinced there is any real support. i will push this onto a back burner for now for when i have both more need and patience for it

mangofreak
05-06-2013, 06:11 PM
One time I got similar error on Moodle. The problem was an empty line where there were not supposed to be any. I deleted the empty line and the memory size problem was gone.

edbr
05-07-2013, 01:22 AM
that sounds interesting . i can only hope as tthe project might just be on a gain

jmichae3
05-08-2013, 05:57 AM
I want to dig further into this is I may, for future reference. perhaps you can submit a bug to php? or I could, if they will take it.

in what was the blank line? for instrance, was it in:
- echo
- heredoc
- '' string
- "" string (this can be on multiple lines by the way, this is how I layout my SQL statements in a nicely formatted way rarther than using a heredoc)
- between statements
- between expression parts
- between conditional parts, say, in an if, while
- between the 3 sections in a for loop
- before the php tags
- after the php tags
- before the start php tag
- after the start php tag
- before the end php tag
- after the end php tag
- ???

where?
thanks. I tend to try to help others with the info I get, so it's not just for me.