I am fairly new to GameMaker HTML5, so I do not completely understand my way around it, but there was one main thing that stood out.
Whenever I try to make a database call, it takes a while to bounce back to GameMaker. I was wondering if this was normal, or if there is a way to increase the speed of the scripts.
To put it in a little more detail, the script I am working with is a simple login script. GameMaker outputs a username and password which are transferred through HTML DOM to a PHP page. From here, the PHP page accesses my database and checks to see if the username and password match up. Then it returns a value.
The problem is that this operation can take anywhere from two to five minutes for the value to be returned.
I have a feeling that it is not normal for this to happen (especially because a PHP call can normally be done within seconds).
Might there be something wrong with my code or does it really take that long for GameMaker to transfer data?
Slow response time
Started by turrule, Dec 01 2011 10:34 PM
4 replies to this topic
#1
Posted 01 December 2011 - 10:34 PM
#2
Posted 02 January 2012 - 08:35 AM
It is not normal, I use basic AJAX calls to submit and retrieve highscores from a database for my games. It can take a second or two sometimes, but certainly not 2-5 minutes (I'm surprised the PHP script did not time out...).
If you posted some of your code, it might be easier to spot the problem. If it helps, I have detailed the complete process in my HTML5 Online Highscores tutorial.
If you posted some of your code, it might be easier to spot the problem. If it helps, I have detailed the complete process in my HTML5 Online Highscores tutorial.
#3
Posted 09 January 2012 - 07:30 AM
Thanks. Sorry if my code is difficult to read.
I still haven't figured out what may be causing the lag time, but I am fairly certain it is something due to the coding and not my information source (I only have about 30 users to deal with).
If you spot anything or have any ideas, I would greatly appreciate it.
I still haven't figured out what may be causing the lag time, but I am fairly certain it is something due to the coding and not my information source (I only have about 30 users to deal with).
If you spot anything or have any ideas, I would greatly appreciate it.
// Call Function
function SQLCommand(url,async) {
if (window.XMLHttpRequest) {
xmlObject = new XMLHttpRequest();
} else {
xmlObject = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlObject.open("GET",url,async);
xmlObject.send(null);
return xmlObject.responseText;
}
// Database Access File [PHP]
session_start();
if (!defined('DB_SERVER')) define('DB_SERVER', "localhost");
if (!defined('DB_USERNAME')) define('DB_USERNAME', "********");
if (!defined('DB_PASSWORD')) define('DB_PASSWORD', "********");
$debug_sql = false;
$link = db_connect();
function db_connect() {
$link = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD)
or die("Could not connect: " . mysql_error());
mysql_select_db(DB_USERNAME, $link)
or die("Could not select db: " . mysql_error());
return $link;
}
function db_close($link) {
mysql_close($link)
or die("Could not close: " . mysql_error());
}
function db_query($query) {
global $debug_sql;
if ($debug_sql) echo "<b>$query</b> <br>";
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
return $result;
}
function db_get_rows($query) {
$rows = db_query($query);
$num_rows = mysql_num_rows($rows);
for ($i=0; $i < $num_rows; $i++) {
$row = mysql_fetch_assoc($rows);
$result[] = $row;
}
mysql_free_result($rows);
if (isset($debug_sql) && $debug_sql) { echo "rows = "; print_r( $result ); echo "<br>"; }
return $result;
}
$logU = $_REQUEST[username];
$logP = $_REQUEST[password];
$find = 0;
$sql = 'SELECT * FROM `users`';
$get_all = db_get_rows($sql);
for($rq_i = 0; $rq_i < count($get_all); $rq_i ++) {
$echo = $get_all[$rq_i];
if(strtolower($logU) == strtolower($echo[username]) && strtolower($logP) == strtolower($echo[password])) {
echo "$echo[username]: $echo[status]!";
$find = 1;
}
}
if($find == 0) {
echo "fail";
}
Edited by turrule, 09 January 2012 - 07:34 AM.
#4
Posted 09 January 2012 - 08:38 AM
Use the MySQL filtering ability, it's designed for it! Rather than retrieving the whole list of users. Code snippet:
Before inserting $logU and $logP into the query, be sure to (at a minimum) mysql_real_escape_string().
$result = mysql_query('select * from users WHERE username = "'.$logU.'" and password = "'.$logP.'"');
if (mysql_num_rows($result) == 0)
{
echo "Username or password is incorrect";
}
else
{
//process result here
}
Before inserting $logU and $logP into the query, be sure to (at a minimum) mysql_real_escape_string().
#5
Posted 09 January 2012 - 04:18 PM
Alright. Thanks.
Sadly, I no longer have any files to test this on, but I will try as soon as I get the chance.
Another problem may have been that I was using the "return" function originally (I'm not sure how that managed to work).
Sadly, I no longer have any files to test this on, but I will try as soon as I get the chance.
Another problem may have been that I was using the "return" function originally (I'm not sure how that managed to work).
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











