Forum Moderators: coopster

Message Too Old, No Replies

Scripts running out of memory?

Hitting the 32MB wall...ouch!

         

tkroll

10:43 am on Sep 3, 2005 (gmt 0)

10+ Year Member



I have a script that makes calls to a web service and pulls down big chunks of XML. I get this error after about the 27th iteration:

"Allowed memory size of 33554432 bytes exhausted (tried to allocate 43 bytes)"

I checked through my code and all the objects are set to NULL after use. Nothing else seems to be wrong. What could be causing this and how do I stop it? I think I need a refresher on how PHP works. I'm using PHP as an Apache module.

I'm not interested in upping PHP memory allocation but finding the root cause.

Thank you!

jatar_k

3:40 pm on Sep 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you cleaning up in/after each iteration?

free up the bigger vars or all of them if you have the option. The answer for me woul dbe to up allowed mem but if you don't want to og that route then you need to clean up your vars and reduce the amount of mem you are using.

tkroll

2:54 am on Sep 6, 2005 (gmt 0)

10+ Year Member



Yes, I am doing this. I read that unset()ing objects in PHP 4 does not work, so I wrote destory methods for all classes involved and call them liberally.

I even tried creating a single object outside the loop and reusing. I got more bang for the buck, but the error persists.

I did not solve the above problem, but worked around it by using exec() inside the loop calling a separate script. This way each iteration frees memory completely.

Thanks!

jatar_k

4:30 pm on Sep 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sounds like a good solution, glad you got it sorted