troubleshooting Question

PHP: Allowed memory size exhausted - memory leak problem

Avatar of andy7789
andy7789 asked on
PHPMySQL Server
7 Comments1 Solution1574 ViewsLast Modified:
Hi X-perts,

I am getting a warning Allowed memory size of 20971520 bytes exhausted and cannot find the code causing memory leak. Pls, take a look at the php code:

<?
require_once('xml_domit_include.php');
require('../Connections/myconn.php');
require_once('../myfunctions.php');
ini_set("memory_limit","20M");
set_time_limit(1600);
mysql_select_db($database_myconn,$myconn);
$mysql = new mysql();
$mysql->conn = $myconn;
echo date('h:i:s') . "\n";
$sql = 'SELECT
  MLSNUM, STREETNAME, STREETNUM, STATE, STREETTYPE, ZIPCODE
FROM
  items_mls t1
  LEFT JOIN items_coord t2 ON t1.MLSNUM = t2.MLSNUMBER
WHERE
  t2.MLSNUMBER IS NULL limit 0, 1000';

$result = $mysql->exSql($sql);

while($items = mysql_fetch_assoc($result)){
$str_name = explode(' ',$items['STREETNAME']);
$street = implode('+',$str_name);
if($items['ZIPCODE'] != '' && $items['ZIPCODE'] != 0){

if($items['STREETTYPE'] != '')$geo = $items['STREETNUM'].'+'.$street.'+'.$items['STREETTYPE'].',+'.$items['ZIPCODE'].',+'.$items['STATE'];
else $geo = $items['STREETNUM'].'+'.$street.',+'.$items['ZIPCODE'].',+'.$items['STATE'];
// activating google parser

// Desired address
$address = "http://maps.google.com/maps/geo?q=$geo&output=xml&key=$map_key";

$location = & new DOMIT_Document();
sleep(1.725);
$success = $location->loadXML($address);

$myArray =& $location->toArray();

$coord = & $location->documentElement->getElementsByPath("//Response/Placemark/Point/coordinates",1);
$stat = & $location->documentElement->getElementsByPath("//Response/Status/code",1);
$status = $stat->getText();
if($status == 200){
$coordinates = $coord->getText();
$c_array=explode(',',$coordinates);
$latitude = $c_array[1];
$longitude = $c_array[0];
//

} else {
$geo = 'na';
$latitude = 0;
$longitude = 0;
}

} else {
//no geocoding done because zipcode is not existing
$status = 999;
$geo = 'na';
$latitude = 0;
$longitude = 0;
}

$sql1 = 'insert into items_coord (MLSNUMBER, code,test,latitude, longitude) values ("'.$items['MLSNUM'].'", "'.$status.'", "'.$geo.'", "'.$latitude.'", "'.$longitude.'")';
$res = $mysql->exSql($sql1);
//mysql_free_result($res); //cannot help in memory leak
}
echo 'finished!';
echo date('h:i:s') . "\n";
?>

It makes about 200-300 correct cycles in the   "while" loop and then stops on the above error.

What is wrong here?

Thanks

A
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 7 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros