Verwerkingssnelheid
Ik ben bezig met het verbeteren van me scripts en de laad snelheid zo beperkt mogelijk te laten.
Ik hoorde van iemand dat ik al mijn dingen in een array of iets dergelijks moest zetten, en aangezien ik er nooit mee heb gewerkt en me het nietl ukte naar tijdje eraan te werken vraag ik ullieo m hulp.
Kortom ik wil dus dat de laadtijd veel lager word
Alvast Bedankt
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php$good1 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '1'"));
$good2 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '2'"));
$good3 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '3'"));
$good4 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '4'"));
$good5 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '5'"));
$good6 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '6'"));
$good7 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '7'"));
$good8 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '8'"));
$good9 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '9'"));
$good10 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '10'"));
if($this_user->lastactive == 0) {
$city = mysql_fetch_object(mysql_query("SELECT * FROM cities WHERE id = '$this_user->city'"));
$worth1 = (($city->good1 * $good1->worth) / 100) * 10;
$worth2 = (($city->good2 * $good2->worth) / 100) * 10;
$worth3 = (($city->good3 * $good3->worth) / 100) * 10;
$worth4 = (($city->good4 * $good4->worth) / 100) * 10;
$worth5 = (($city->good5 * $good5->worth) / 100) * 10;
$worth6 = (($city->good6 * $good6->worth) / 100) * 10;
$worth7 = (($city->good7 * $good7->worth) / 100) * 10;
$worth8 = (($city->good8 * $good8->worth) / 100) * 10;
$worth9 = (($city->good9 * $good9->worth) / 100) * 10;
$worth10 = (($city->good10 * $good10->worth) / 100) * 10;
$trade1 = rand(($city->good1 * $good1->worth) - $worth1, ($city->good1 * $good1->worth) + $worth1);
$trade2 = rand(($city->good2 * $good2->worth) - $worth2, ($city->good2 * $good2->worth) + $worth2);
$trade3 = rand(($city->good3 * $good3->worth) - $worth3, ($city->good3 * $good3->worth) + $worth3);
$trade4 = rand(($city->good4 * $good4->worth) - $worth4, ($city->good4 * $good4->worth) + $worth4);
$trade5 = rand(($city->good5 * $good5->worth) - $worth5, ($city->good5 * $good5->worth) + $worth5);
$trade6 = rand(($city->good6 * $good6->worth) - $worth6, ($city->good6 * $good6->worth) + $worth6);
$trade7 = rand(($city->good7 * $good7->worth) - $worth7, ($city->good7 * $good7->worth) + $worth7);
$trade8 = rand(($city->good8 * $good8->worth) - $worth8, ($city->good8 * $good8->worth) + $worth8);
$trade9 = rand(($city->good9 * $good9->worth) - $worth9, ($city->good9 * $good9->worth) + $worth9);
$trade10 = rand(($city->good10 * $good10->worth) - $worth10, ($city->good10 * $good10->worth) + $worth10);
mysql_query("UPDATE users SET trade1 = '$trade1' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade2 = '$trade2' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade3 = '$trade3' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade4 = '$trade4' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade5 = '$trade5' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade6 = '$trade6' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade7 = '$trade7' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade8 = '$trade8' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade9 = '$trade9' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade10 = '$trade10' WHERE id = '$this_user->id'");
}
?>
$good2 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '2'"));
$good3 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '3'"));
$good4 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '4'"));
$good5 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '5'"));
$good6 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '6'"));
$good7 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '7'"));
$good8 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '8'"));
$good9 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '9'"));
$good10 = mysql_fetch_object(mysql_query ("SELECT * FROM trades WHERE id = '10'"));
if($this_user->lastactive == 0) {
$city = mysql_fetch_object(mysql_query("SELECT * FROM cities WHERE id = '$this_user->city'"));
$worth1 = (($city->good1 * $good1->worth) / 100) * 10;
$worth2 = (($city->good2 * $good2->worth) / 100) * 10;
$worth3 = (($city->good3 * $good3->worth) / 100) * 10;
$worth4 = (($city->good4 * $good4->worth) / 100) * 10;
$worth5 = (($city->good5 * $good5->worth) / 100) * 10;
$worth6 = (($city->good6 * $good6->worth) / 100) * 10;
$worth7 = (($city->good7 * $good7->worth) / 100) * 10;
$worth8 = (($city->good8 * $good8->worth) / 100) * 10;
$worth9 = (($city->good9 * $good9->worth) / 100) * 10;
$worth10 = (($city->good10 * $good10->worth) / 100) * 10;
$trade1 = rand(($city->good1 * $good1->worth) - $worth1, ($city->good1 * $good1->worth) + $worth1);
$trade2 = rand(($city->good2 * $good2->worth) - $worth2, ($city->good2 * $good2->worth) + $worth2);
$trade3 = rand(($city->good3 * $good3->worth) - $worth3, ($city->good3 * $good3->worth) + $worth3);
$trade4 = rand(($city->good4 * $good4->worth) - $worth4, ($city->good4 * $good4->worth) + $worth4);
$trade5 = rand(($city->good5 * $good5->worth) - $worth5, ($city->good5 * $good5->worth) + $worth5);
$trade6 = rand(($city->good6 * $good6->worth) - $worth6, ($city->good6 * $good6->worth) + $worth6);
$trade7 = rand(($city->good7 * $good7->worth) - $worth7, ($city->good7 * $good7->worth) + $worth7);
$trade8 = rand(($city->good8 * $good8->worth) - $worth8, ($city->good8 * $good8->worth) + $worth8);
$trade9 = rand(($city->good9 * $good9->worth) - $worth9, ($city->good9 * $good9->worth) + $worth9);
$trade10 = rand(($city->good10 * $good10->worth) - $worth10, ($city->good10 * $good10->worth) + $worth10);
mysql_query("UPDATE users SET trade1 = '$trade1' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade2 = '$trade2' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade3 = '$trade3' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade4 = '$trade4' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade5 = '$trade5' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade6 = '$trade6' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade7 = '$trade7' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade8 = '$trade8' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade9 = '$trade9' WHERE id = '$this_user->id'");
mysql_query("UPDATE users SET trade10 = '$trade10' WHERE id = '$this_user->id'");
}
?>
Gewijzigd op 01/01/1970 01:00:00 door Rick
Code (php)
1
2
3
4
2
3
4
<?php
mysql_query("UPDATE users SET trade1 = '$trade1', trade2 = '$trade2' WHERE id = '$this_user->id'");
//en de rest van je velden zelf invullen
?>
mysql_query("UPDATE users SET trade1 = '$trade1', trade2 = '$trade2' WHERE id = '$this_user->id'");
//en de rest van je velden zelf invullen
?>
Daarnaast heb ik het idee dat je database niet genormaliseerd is, ik weet niet of de website al volop in gebruik is, niet, dan is het zinvol om je database te normaliseren, want zodra jij kolommen gaat nummeren ben je verkeerd bezig.
En dat scheelt dus ook in snelheid.
Code (php)
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
<?php
$query = "SELECT * FROM trades";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_object($result)){
$good[] = $row->worth;
}
?>
$query = "SELECT * FROM trades";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_object($result)){
$good[] = $row->worth;
}
?>
Dan is $good wel een array geworden, maar dit is vele malen efficienter...
En zo kun je het hele script aanpassen, die laatste updates kunnen bijvoorbeeld ook prima in één query.
Tip: gebruik altijd mysql_fetch_assoc in plaats van mysql_fetch_object. De eerste is veel sneller.