cmazur Posted September 7, 2007 Share Posted September 7, 2007 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 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; } Quote Link to comment https://forums.phpfreaks.com/topic/68359-memory-leaks/ Share on other sites More sharing options...
deadimp Posted September 7, 2007 Share Posted September 7, 2007 This may not be the cause of that memory usage, but why are you connecting to your database in your execute_mysql() statement? It'd be better if you connected outside of that function so you don't have to write as much for that function - in fact, there's not much use for it. As for Sajax and all that, I'm not sure, since I haven't worked with it much. But why are you using a timer to execute ajax requests? Could that possibly overlap? Plus, why do you define InitializeTimer() with secs=1, in which you call StartTheTimer(), which then checks if secs==1, where you could just move that code to InitializeTimer() without the conditional in it. Do you know what happens when you try a different browser? Quote Link to comment https://forums.phpfreaks.com/topic/68359-memory-leaks/#findComment-343719 Share on other sites More sharing options...
cmazur Posted September 7, 2007 Author Share Posted September 7, 2007 This may not be the cause of that memory usage, but why are you connecting to your database in your execute_mysql() statement? It'd be better if you connected outside of that function so you don't have to write as much for that function - in fact, there's not much use for it. As for Sajax and all that, I'm not sure, since I haven't worked with it much. But why are you using a timer to execute ajax requests? Could that possibly overlap? Plus, why do you define InitializeTimer() with secs=1, in which you call StartTheTimer(), which then checks if secs==1, where you could just move that code to InitializeTimer() without the conditional in it. Do you know what happens when you try a different browser? Thanks, I'll take into consideration the suggestions you've made. Any other thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/68359-memory-leaks/#findComment-343725 Share on other sites More sharing options...
cmazur Posted September 7, 2007 Author Share Posted September 7, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/68359-memory-leaks/#findComment-343806 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.