Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
OK so i have a very busy website, which used to use a flat file database system for members
i have just covnerted it to run completely from MYSQL, however now with 200 users online MYSQL is going crazy
Im fairlly new to MYSQL, so im not aware of common programming issues that may cause crashes or lock ups
Load = 20, 30, 40..... i look at TOP and see 279 Processes
CPU states: cpu user nice system irq softirq iowait idle
total 78.2% 0.0% 20.3% 0.5% 0.7% 0.0% 0.0%I also see a lot of mysql <defunct> in TOP
Here is an example of the type of commands that are being run by each user every time they click a link, so its 200 X whats below near enoughAt first i thoguht it might be because i never had any 'LIMIT 0,1' its the commands, but as you can see ive added them now
the DATABASE in questions is the members one, its 4.5MB and has 26,000 users
// fullname
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$fullname=mysql_result($result,'id',"fullname");
// username
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$usered=mysql_result($result,'id',"username");// nickname
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$nickname=mysql_result($result,'id',"nickname");
// visits
$query="SELECT * FROM members WHERE username='$page' LIMIT 0,1";
$result=mysql_query($query);
$visits=mysql_result($result,'id',"visits");
$browsin="UPDATE members SET browsing = '$rowed' WHERE username = '$usered'";
mysql_query($browsin) or die(mysql_error());$lastact="UPDATE members SET lastact = '$dated' WHERE username = '$usered'";
mysql_query($lastact) or die(mysql_error());
$song="UPDATE members SET lastsongs = '$lastsongsdone' WHERE username = '$usered'";
mysql_query($song) or die(mysql_error());
mysql_close();Any help would be greatly appreciate, my site is basically dying, takes 15 seconds for each page to load....
Jamie McCoy

Instead of mssql_query, you should use mssql_fetch_array which will be faster and (in a single querry) put all the info into an associative array.
I use Perl instad of php, so you may need to verify if this syntax is correct.
$query="SELECT fullname, username, nickname, vists FROM members WHERE username = '$page' LIMIT 0,1";
$result = mssql_fetch_array($query) or die("could not query the database");Now, you can access the info via
$result{'fullname'}
$result{'username'}
$result{'nickname'}
$result{'visits'}

The UPDATE should be done in a similar manor, meaning use a single sql update command instead of each of those individual ones.
By making both of those changes, you should dramatically increase its efficiency.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |