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!