memory - How do I tell PHP to get rid of load_file data after it's used?

871

Here is my PHP. It runs through a bunch of URLs to get similar data (current homeruns from baseball player profiles). However, I'm getting 'Allowed memory size exhausted', which leads me to think that PHP is just aggregating all this load_file data, even after I've used $html->find on it to get the data I want. How can I tell PHP to stop using data from load_file after I've already echo'ed out what I need?

include('simple_html_dom.php');

        $json = file_get_contents("http://example.com/homeruns.json");

        $elements = json_decode($json);

        foreach ($elements as $element){
                $html = new simple_html_dom();
                $html->load_file($element->profileurl);
                $currenthomeruns = $html->find('.homeruns .current',0);
                echo $element->name, " currently has the following number of homeruns: ", strip_tags($currenthomeruns); 
        }
295

Answer

Solution:

at the end of your loop, do unset($html);

People are also looking for solutions to the problem: php - Array being replaced rather than added

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.