Sponsored Content
Top Forums Web Development PHP Fatal error: Allowed memory size of 134217728 bytes exhausted Post 302468375 by Neo on Tuesday 2nd of November 2010 01:33:55 PM
Old 11-02-2010
OK, finally, 8 months after posting this php memory bug, I figured it out, hahaha.

Basically, I used the PHP error_log() function to print the memory allocation using memory_get_usage() and discovered that an array was using a lot of memory, and traced it to $string (using strlen($string) in the debug log) that was passed to the function used in a regex to create the array.

As a temporary fix, I created a PHP conditional to test the memory usage and avoid the offending foreach statement until I could come up with a solution (debugging the entire process, step-by-step).

The solution was to simply define MAX_STR and take a sub string of the huge $string with substr($string,0,MAX_STR), which was using all the memory in the foreach loop in the function.


Then, to clean up, I defined MAX_MEM to insure that the maximum memory of this PHP thread would alway be less than the max PHP memory allocated in the php.ini file.

PHP Code:
define('MAX_STR',512000);
define('MAX_MEM',96000000);
$string substr($string,0,MAX_STR);
if(
memory_get_usage() < MAX_MEM){//blah blah} 
Housekeeping work... done!
 

7 More Discussions You Might Find Interesting

1. AIX

How to increase memory size allowed to one process

Hi, I have migrated some processing from true64 --> AIX 5.3. my problem is to process large files in memory by diff or awk program. I need to load app. 1.3 GB of data into memory but it fails that there is not enough memory. I need following: diff file1 file2 orig. aix diff err... (2 Replies)
Discussion started by: Petr
2 Replies

2. Shell Programming and Scripting

Memory exhausted in awk

Dear All, I have executed a awk script in linux box which consists of 21 Million records.And i have two mapping files of 500 and 5200 records.To my surprise i found an error awk: cmd. line:19: (FILENAME=/home/FILE FNR=21031272) fatal: Memory exhausted. Is there any limitation for records... (3 Replies)
Discussion started by: cskumar
3 Replies

3. Shell Programming and Scripting

Compare lines in two files (Memory getting exhausted)

Hi, Could someone please help me with the best approach to compare lines from one file to another? Here is how I have entries - File 1 a1 a2 a3 a4 a9 a10 a15 File2 a5 a6 a15 (5 Replies)
Discussion started by: sncoupons
5 Replies

4. Solaris

PHP 5.3 compile on Solaris 10 : make distclean :: fatal error

I'm trying to install PHP 5.3 on Solaris 10 . I'm using etc/apache2 and installed mysql 5.1.39. When I tried to compile PHP 5.3, with the following configure text, ./configure --with-mysql=/usr/local/mysql \ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-zlib-dir=/usr/local \... (21 Replies)
Discussion started by: ppa108
21 Replies

5. UNIX for Advanced & Expert Users

Out of Memory error when free memory size is large

I was running a program and it stopped and showed "Out of Memory!". at that time, the RAM used by this process is around 4G and the free memory size of the machine is around 30G. Does anybody know what maybe the reason? this program is written with Perl. the OS of the machine is Solaris U8. And I... (1 Reply)
Discussion started by: lilili07
1 Replies

6. Shell Programming and Scripting

Error PHP Fatal error: Allowed memory size of 67108864 bytes exhausted(tried to allocate 401 bytes)

While running script I am getting an error like Few lines in data are not being processed. After googling it I came to know that adding such line would give some memory to it ini_set("memory_limit","64M"); my input file size is 1 GB. Is that memory limit is based on RAM we have on... (1 Reply)
Discussion started by: elamurugu
1 Replies

7. What is on Your Mind?

PHP Fatal Errors During SSL Cert Management - PHP Fatal error: xc_fcntl_mutex failed

Today, I noticed some errors in our SSL cert renewal log files, mostly related to domains where the IP address had changed. Concerned about this, rebuilt out SSL cert, which normally goes well without a hiccup. However, for today, for some reason which I cannot explain, there was a PHP error... (0 Replies)
Discussion started by: Neo
0 Replies
SHM_ATTACH(3)								 1							     SHM_ATTACH(3)

shm_attach - Creates or open a shared memory segment

SYNOPSIS
resource shm_attach (int $key, [int $memsize], [int $perm = 0666]) DESCRIPTION
shm_attach(3) returns an id that can be used to access the System V shared memory with the given $key, the first call creates the shared memory segment with $memsize and the optional perm-bits $perm. A second call to shm_attach(3) for the same $key will return a different shared memory identifier, but both identifiers access the same underlying shared memory. $memsize and $perm will be ignored. PARAMETERS
o $key - A numeric shared memory segment ID o $memsize - The memory size. If not provided, default to the sysvshm.init_mem in the php.ini, otherwise 10000 bytes. o $perm - The optional permission bits. Default to 0666. RETURN VALUES
Returns a shared memory segment identifier. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 5.3.0 | | | | | | | This function now returns a resource instead of | | | an integer. | | | | +--------+---------------------------------------------------+ NOTES
Note This function used to return an integer value prior to PHP 5.3.0. To achieve the same value in a portable manner, the return value can be cast to an integer like: Example #1 <?php // Create a temporary file and return its path $tmp = tempnam('/tmp', 'PHP'); // Get the file token key $key = ftok($tmp, 'a'); // Attach the SHM resource, notice the cast afterwards $id = shm_attach($key); if ($id === false) { die('Unable to create the shared memory segment'); } // Cast to integer, since prior to PHP 5.3.0 the resource id // is returned which can be exposed when casting a resource // to an integer $id = (integer) $id; ?> SEE ALSO
shm_detach(3), ftok(3). PHP Documentation Group SHM_ATTACH(3)
All times are GMT -4. The time now is 05:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy