Hi,
Weird issue. I recently upgraded server hardware in the server running an online game I am working on.
It is an Athlon Thunderbird 1200 Mhz, 256 MB DDR Ram, and ULTRA SCSI-3 WIDE LVD harddrive.
The server has been rebuilt with latest releas Gentoo linux, and packages for MySQL, OpenSSL, and PHP 4.2.2.
Phpinfo here
The problem is this.:rolleyes:
I do a random select for monster encounters like:
SELECT * FROM monster WHERE areacode=9 ORDER BY RAND() LIMIT 1
I run the query through PHP mysql_connect and return the selected record.
The problem is PHP returns only some of the records in the table - certain records are never selected.
Running the SQL query from the Mysql CLI, gives an even spray of matches with all records.
Same thing if I do a loop or return all records in PHP (no LIMIT in sql). Though even if I return all records - certain records never gets selected first.
The thing is I don't need more than one record, so I want to keep the LIMIT 1 in the SQL - to limit memory usage and get cleaner looking code.
My PHP code worked fine until before the upgrade, I think. It definitely works fine in my development environment (Which is IIS PHP and MySQL on Windows 2000).
So basically I don't think there is anything wrong with the code itself.
I made a small test script to illustrate the problem here.
This is what the script looks like:
<?php
include("includes/db_sql.inc");
$i = 400;
$tmp = Array();
while($i>0)
{
$i--;
$cn = new DB_SQL;
$sql = "SELECT * FROM monster WHERE areacode=9 ORDER BY RAND() LIMIT 1";
$cn->query($sql);
while($cn->next_record())
{
if (!isset($tmp[$cn->record["name"]]))
{
$tmp[$cn->record["name"]]["no"]=1;
$tmp[$cn->record["name"]]["name"]=$cn->record["name"];
}
$tmp[$cn->record["name"]]["no"]++;
}
}
foreach ($tmp as $foo)
{
echo $foo["name"].":".$foo["no"]."<br>";
}
?>
If you run it repeatedly you will see that Wurm for example never gets selected first. Though the random spread from the loop looks okay.
Any ideas what might be causing this? I'm thinking some kind of timing issue with PHP opening the connection and mysql seeding its random generator???
Please guys, any help would be super!!!
ps. I know I could do this by selecting the whole table and picking a random row from PHP, but that would bloat my code, and memory consumption - and this is one hungry app, so I am trying to minimise load. ds.
Regards
Hans Petersson