Jump to content

Sajax Memory Leaks?


cmazur

Recommended Posts

Hey All,

 

I've got some code that constantly updates a table on my web page. There is an update every 250 milliseconds.

The problem is that my memory usage for IE is outrageous after about 5 minutes of running (roughly 600 mb of memory used).

 

I'm not sure if this is a problem with my PHP script that pulls the data or the use of Sajax.

 

My code is below:

 

PHP Script to pull data:

 


<?php
require("Sajax.php");
session_start();

//Execute a SQL query and return a row
function execute_mysql($sql)
{
	//Connect to Database
	$db_host = "host";
	$db_user = "username";
	$db_pass = "password";
	$db_name = "table";

	$link = mysql_connect( $db_host, $db_user, $db_pass );

	if(!$link)
	{
		unset($link);
		return -1;	//database connection failed
	}
	else
	{
		$db_selected = mysql_select_db( $db_name );
		if(!$db_selected)
		{
			mysql_close($link);
			unset($link);			
			unset($db_selected);
			return -1;	//database not selected
		}


		$res = mysql_query( $sql );
		if(!$res)
		{
			mysql_close($link);
			unset($link);
			unset($db_selected);
			unset($res);
			return -1;	//bad query
		}

		if(mysql_num_rows($res) == 0)
		{
			mysql_close($link);
			unset($link);
			unset($db_selected);
			unset($res);
			return -1;	//empty query results
		}

		$row = mysql_fetch_assoc($res); 

		mysql_close($link);
		unset($link);
		unset($db_selected);
		unset($res);

		return $row;
	}
}

//All 12 of the functions to be exported are in this format 
            // They just pull different data

function f1()
{
	$sql = "SELECT STATEMENT;";
	$row = execute_mysql($sql);
	echo "$row['col2']";

	unset($sql);
	unset($row);
}

//Setup the Ajax
sajax_init();

sajax_export("f1");
sajax_export("f2");
sajax_export("f3");		
sajax_export("f4");
sajax_export("f5");		
sajax_export("f6");
sajax_export("f7");		
sajax_export("f8");
sajax_export("f9");		
sajax_export("f10");
sajax_export("f11");		
sajax_export("f12");				

sajax_handle_client_request();
?>

 

The code the contains the Javascript for the calling of the functions and the timer event

 

<script type='text/javascript'>

<?php
	sajax_show_javascript();
?> 

var secs;
var timerID = null;
var timerRunning = false;
var delay = 250;

function InitializeTimer()
{
	secs = 1;
	StopTheClock();
	StartTheTimer();
}

function StopTheClock()
{
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
	secs = 1;
}

function StartTheTimer()
{
	if(secs == 1)
	{
		<?php
			//Set the initial values for the bytes and packets of each feed
			f1();
			f2();
			f3();
			f4();
		?>

	}

	//document.getElementById("divMem").innerHTML = "<?php echo memory_get_usage(false); ?>";

	//self.status = secs + " Updates Performed";
	secs = secs + 1;
	timerRunning = true;

	x_f1(f1_cb);
	x_f2(f2_cb);

	x_f3(f3_cb);
	x_f4(f4_cb);	

	x_f5(f5_cb);
	x_f6(f6_cb);

	x_f7(f7_cb);
	x_f8(f8_cb);

	x_f9(f9_cb);
	x_f10(f10_cb);

	x_f11(f11_cb);
	x_f12(f12_cb);

	timerID = self.setTimeout("StartTheTimer()", delay);
}

function f1_cb(f1)
{
	var temp = f1;
	if(temp != -1)	
		document.getElementById("lblF1").innerHTML = temp;
}

Link to comment
https://forums.phpfreaks.com/topic/68358-sajax-memory-leaks/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.