jakebur01 Posted April 6, 2009 Share Posted April 6, 2009 How can I free up the memory on this script to keep from getting " 0 - 20 20 - 40 PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 1992 bytes) in ?" $total_rows = mysql_num_rows(mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK'", $db)); $rows_per_loop = 20; $total_loops = ceil($total_rows/$rows_per_loop); // run the loop, while loop counter is less than the total number of loops: for($s=0; $s<$total_loops; $s++) { // get the numbers for the limit, // start is just the current loop number multiplied by the rows per loop // and end is loop counter + 1, multiplied by the rows per loop $limit_start = $rows_per_loop*$s; $limit_end = $rows_per_loop*($s+1); $result = mysql_query("SELECT * FROM zip_code where `state_prefix` = 'OK' LIMIT $limit_start, $limit_end") or die(mysql_error()); while($myrow = mysql_fetch_array ($result)) { $zip=$myrow['zip_code']; // get DOM from URL or file $html=file_get_html("http://www.mysite.com/age.asp?transaction=search&template=map_search&search1=0&pwidth=400&pheight=700&proxIconId=400&proxIcons=1&search2=0&search3=1&country=US&searchQuantifier=AND&address=&city=&stateProvince=+&postalCode=$zip&radius=500&x=78&y=16"); $i = 0; $tmp = $html->find('span[class=mqEmp], span[class=Black11]'); $cnt = count($tmp) - 1; foreach($tmp as $e) { if($i > 0 && $i < $cnt){ $outputstring=$e->plaintext; $outputstring=$outputstring. "\t"; fwrite($fp, $outputstring, strlen($outputstring)); if ($i % 8 == 0) { fwrite($fp, $other, strlen($other)); } } $i++; } } // now that we've run those, let's clear the results so that we don't run out of memory. mysql_free_result($result); // show where we are at echo $limit_start,' - ',$limit_end,'<br />'; sleep(1); // give PHP a little nap to keep from overloading server ob_flush(); // as recommended by MadTechie, in case we go beyond the max execution time flush(); // add flush, to make sure it is outputted } fclose($fp); Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/ Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 bump... Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803087 Share on other sites More sharing options...
Fruct0se Posted April 7, 2009 Share Posted April 7, 2009 Edit your php.ini file, find memory_limit and set it to a higher value. Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803089 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 I have tried that. I was referring to something that would maybe release the memory more often or something. Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803105 Share on other sites More sharing options...
ohdang888 Posted April 7, 2009 Share Posted April 7, 2009 idk, but just curious...would sleep() really ever help the server load? Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803109 Share on other sites More sharing options...
9three Posted April 7, 2009 Share Posted April 7, 2009 Errors like these usually come from loops. You might want to try and edit your loop to do less irritations. Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803112 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 Is there any other way to give it a break in between? Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803117 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803353 Share on other sites More sharing options...
jakebur01 Posted April 7, 2009 Author Share Posted April 7, 2009 How could I make this like refresh to a new page limiting 25 each time? Like..... run 25 then redirect to: mypage.php?offset=25 run 25 more then redirect to mypage.php?offset=50 and so on.. Quote Link to comment https://forums.phpfreaks.com/topic/152889-solved-using-up-too-much-memory/#findComment-803359 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.