Note that there are some explanatory texts on larger screens.

plurals
  1. POphp wait till previous function has finished
    text
    copied!<p>I'm trying to create some xml , basically by reading rss feeds and adding to them some custom tags. I've made a function that contains my code, and now i want to call the function several times with different rss urls. Each call will produce a different .xml file.<br> I use DOMDocument to load and parse the rss, and simple_html_dom to load and parse the link of each rss item to get some content from the html.<br> Here is a simplified example of my code: </p> <pre><code>&lt;?php include('simple_html_dom.php'); load_custom_rss('http://www.somesite.com/rssfeed/articles', 'articles.xml'); load_custom_rss('http://www.somesite.com/rssfeed/jobs', 'jobs.xml'); load_custom_rss('http://www.somesite.com/rssfeed/press', 'press.xml'); //up to 20 similar function calls here... function load_custom_rss($link, $filename){ $doc = new DOMDocument(); $doc-&gt;load($link); $newDoc = new DOMDocument('1.0', 'UTF-8'); $rss = $newDoc-&gt;createElement('rss'); $channel = $newDoc-&gt;createElement('channel'); $newDoc-&gt;appendChild($rss); $rss-&gt;appendChild($channel); foreach ($doc-&gt;getElementsByTagName('item') as $node) { //here is some code to read items from rss xml / write them to new xml document. //Code missing for simplicity //Next lines used to get some elements from the html of the item's link $html = new simple_html_dom(); html-&gt;load_file($node-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue); $ret = $html-&gt;find('#imgId'); } $newDoc-&gt;formatOutput = true; $fh = fopen($filename, 'w') or die("can't open file"); fwrite($fh, $newDoc-&gt;saveXML()); fclose($fh); unset($doc); //unset ALL variables and objects created in this function... //........ }//function end ?&gt; </code></pre> <p>My problem is that each call of the function consumes quite an amount of memory, so after the 3rd or 4th call of the function apache throws Fatal Error, as the script consumes memory amount bigger than the memory_limit, even though i unset ALL variables and objects created in the function. If i reduce the function calls to 1 or 2 everything works fine.<br> Is there any way it could work? I was thinking about each function call waits for the previous to finish before starting, but how could this be done?</p> <p>Hope somebody could help. thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload