473,413 Members | 1,802 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,413 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 12422
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.