473,248 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,248 software developers and data experts.

memory allocation problems in PHP and how to optimize?

PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory. I want to know why my script has
gotten so out-of-control when it comes to memory use. I'm assuming
there must be some array somewhere that is bloating up with
information, perhaps information that I assumed was being detroyed. It
could be a rather small mistake, causing a big problem. But how does
one debug memory allocation in PHP? There is no way, that I'm aware
of, to see the memory usage of all variables at all times.

Even if I had the patience to hit every variable in all my code with
var_dump(), just to get a rough estimate of their sizes, that still
wouldn't help, because the moment the var goes over 8 megs, it
crashes, before var_dump would have the time to print the info to me.
Jul 17 '05 #1
2 12415
lawrence wrote:
PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory.

[...]
check memory_get_usage()

maybe put it in a function:

<?php
function debug_memory($reason) {
echo $reason, ': ', memory_get_usage();
}
?>

and then call it before/after selected instructions

<?php
$a = $b; debug_memory('array copy');

$b = NULL; debug_memory('NULLified array');
?>
HTH

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #2
Pedro <he****@hotpop.com> wrote in message news:<bm************@ID-203069.news.uni-berlin.de>...
lawrence wrote:
PHP keeps throwing out-of-memory errors on me. By default PHP only
allows a script 8 megs of memory.

[...]
check memory_get_usage()


Outstanding. I searched on Google and came up with nothing. Thanks
much, this will make debugging much easier.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: DLPnet | last post by:
Hello, I m working on Windows and Mac in C++. My application uses a lot of memory since it s dealing with a lot of images. So I load images in a cache when needed and if I haven t enough...
4
by: PaulR | last post by:
Hi, We have a Server running SLES 8 and 3GB memory, with 1 DB2 instance and 2 active Databases. General info... DB2level = "DB2 v8.1.0.72", "s040914", "MI00086", and FixPak "7" uname -a =...
74
by: ballpointpenthief | last post by:
If I have malloc()'ed a pointer and want to read from it as if it were an array, I need to know that I won't be reading past the last index. If this is a pointer to a pointer, a common technique...
7
by: Ravi | last post by:
I created a program just to amuse me. I consumes a lot of memory and never gives it up: #incluse <stdio.h> #include <stdlib.h> int main(void) { void *a; while(1) a = malloc(99999); }
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
34
by: jacob navia | last post by:
Suppose that you have a module that always allocates memory without ever releasing it because the guy that wrote it was lazy, as lazy as me. Now, you want to reuse it in a loop. What do you do?...
3
by: rupert.thurner | last post by:
the edgewall trac release 0.11 is blocked now since more than one month for a memory leak nobody is able to find, see http://groups.google.com/group/trac-dev/browse_thread/thread/116e519da54f16b...
0
by: Steve Holden | last post by:
Hank @ITGroup wrote: Well, now you've told us a little more about your application I can understand that you need to be careful with memory allocation. The best thing you can do is to ensure...
8
by: rahul | last post by:
How is the memory allocated for structures? I need to optimize the memory usage and bit fields are not doing the trick. Any details about the memory allocation for the structures would be a...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.