Click to See Complete Forum and Search --> : Memory/working space used by strings


gizmo
10-24-2007, 02:51 PM
I have a program written in PHP to compare the images on my site called by 'img' are the same as in the image folders. It flags up unused and missing images and also checks the image size is as declared. I added a few lines of code to exclude images in 'href' links and although it worked, the program ran out of memory before completion.
I suspect that this was not due to the extra lines of code (as I have commented them out and added even more since). It uses a lot of string functions, so I suspect that I am out of working space. If so, is there a way of reclaiming that space for further use?

sitehatchery
10-24-2007, 04:49 PM
I might be missing what your goal is, but what if you did:

ob_start('ob_gzhandler'); at the top of the page to save some bandwidth and load the page faster.

Also, you mentioned something about comparing images. I might be misunderstanding, but what if you compared the string length of the file, or compared the strings of the image file?

$data= file_get_contents('http://media.washingtonpost.com/wp-srv/photo/homepage/hp10-24-07j.jpg');
$len=strlen($data);

or
$data1=file_get_contents('image1.jpg');
$data2=file_get_contents('image2.jpg');

if(strmp($data1, $data2)==-1)) { ... do something if they don't match ... }

bokeh
10-24-2007, 05:28 PM
If you are out of RAM your script is probably stuck in a loop.Or maybe the RAM limit is too low. In the current version the default is 128MB

gizmo
10-25-2007, 05:17 AM
sitehatchery, my goal is to free up some memory and make it available for use. The program reads each page of my site and extracts the parameters relating to each 'img' statement. It compares them with the actual images using the 'getimagesize' command.
bokeh, the program doesn't stick in a loop, but stops with a message starting:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 7223295 bytes) in....
Now guys, I reckon that there is insufficient working space from past string processing and was wondering if there was a way to free up space no longer in use.

Lubox
10-25-2007, 07:31 AM
Hi

I had this error in an earlier version of PHP for no reason, and the apache restartet itself afterwards. What version are you using?

Lubox

bokeh
10-25-2007, 09:14 AM
Can I see the code? Are you unsetting the variables and freeing the RAM usage properly after each task?