index.php <html dir="rtl"> <? $id= $_GET[id]; include "config.php"; $id= $_REQUEST['id']; $w=@mysql_query("select * from info"); while($row=@mysql_fetch_array($w)) { ?> <head> <meta http-equiv="Content-Language" content="ar-eg"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1256"> <title><? echo $row[a1]; ?></title> <META name="keywords" content="<? echo $row[a2]; ?>"> <META NAME="description" content="<? echo $row[a3]; ?>"> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <meta name="robots" content="index, follow"> <meta name="verify-v1" content="AWfsXRtlip9DLoOXwFsXadLn6B/fxANtvgpE7uaj1C0=" /> <meta name="Robots" content="index,follow" /> <link id="style" rel="stylesheet" href="style1/style.css" type="text/css" media="screen" /> <link rel="stylesheet" href="style1/menu.css" type="text/css" media="screen" /> <link rel="stylesheet" href="style1/topic.css" type="text/css" media="screen" /> <script type="text/javascript" src="javascript/navigation.js"></script> <link rel="stylesheet" href="style1/pagination.css" type="text/css" media="screen" /> </head> <?php include"config.php"; if(!(isset($page))) { $page=1; } else { $page=$_GET['page']; } include "config.php"; $w=@mysql_query("select * from info "); while($row=@mysql_fetch_array($w)) { $max=$row[max]; $from=($max*$page)-$max; $sql = mysql_query("select * from home"); $num_sql = mysql_num_rows($sql); } ?> <body> <? require("hd.php"); ?> <div id="content"> <? } $sql1 = mysql_query("select * from home ORDER BY id DESC limit $from,$max"); $num_sql1 = mysql_num_rows($sql1); $pages=ceil($num_sql/$max); while($row = mysql_fetch_array($sql1)){ ?> <div id="topic"> <table style="border-collapse: collapse;" border="0" cellpadding="0" width="185" id="table5"> <tr> <td> <img alt="" src="pro/cats_03.gif" height="50" width="13"></td> <td background="cats1_01.gif"><center><center> <font color="#ffffff"><a href="Download<? echo $row[0]; ?>.html" target="_blank"> <font color="#FFFFFF"><span style="text-decoration: none"><? echo $row[2]; ?></span></font></a></font></center></center></td> <td> <img alt="" src="cats_01.gif" height="50" width="13"></td> </tr> <tr> <td background="cats_066.gif" valign="top"> </td> <td dir="rtl" bgcolor="#f7fbf5" valign="top" width="91%"> <table style="border-collapse: collapse;" border="2" bordercolor="#f7fbf5" cellpadding="0" cellspacing="0" width="100%" id="table6"> <tr> <td height="22"> <p align="center"> <a href="Download<? echo $row[0]; ?>.html" target="_blank"> <img border="0" src="<? echo $row[1]; ?>" alt="<? echo $row[2]; ?>" width="226" height="194"></a></td> </tr> <tr> <td> <p align="center"> <textarea rows="3" name="S1" cols="28" style="color: #06A9EB; font-size: 9pt; font-weight: bold"><? echo $row[4]; ?></textarea></td> </tr> <tr> <td> <p align="center"><span lang="ar-eg"><font size="2"> تم التØÙ…يل <font color="#FF0000"><? echo $row[a7]; ?></font> مره</font></span></td> </tr> </table> </td> <td align="right" background="cats_044.gif" valign="top"> </td> </tr> <tr> <td><img alt="" src="cats_09.gif"></td> <td align="left" background="cats_088.gif"> <p align="center"> <a href="cat<? echo $row[cat]; ?>.html"> <img border="0" src="cat/<? echo $row[cat]; ?>.gif" width="126" height="30"></a></td> <td><img alt="" src="cats_07.gif"></td> </tr> </table> </div> <? } ?><? require("pages.php"); require("fd.php"); ?> PHP: config.php <? if ( phpversion() >= "4.2.0"){ extract($_POST); extract($_GET); extract($_SERVER); extract($_COOKIE); } $dbhost='localhost'; $dbuser='root'; $dbpass='asdasd'; $dbname='dd'; $con=mysql_connect($dbhost,$dbuser,$dbpass)or die ("لايوجد اتصال بالقاعده"); $sql=mysql_select_db($dbname,$con) or die ("لم يتم ØªØØ¯ÙŠØ¯ قاعده بيانات"); ?> <? $sql=@mysql_query("select*from site"); $row=@mysql_fetch_array($sql); if($row['stat']==1) { echo $row['msg']; } ?> PHP: Database CREATE TABLE IF NOT EXISTS `home` ( `id` int(4) NOT NULL AUTO_INCREMENT, `a1` text NOT NULL, `a2` text NOT NULL, `a3` text NOT NULL, `a4` text NOT NULL, `a5` text NOT NULL, `a6` text NOT NULL, `a7` text NOT NULL, `cat` varchar(100) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=761 ; PHP: +-------+-------------+-----------+------------+---------+------+--------------+--------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +-------+-------------+-----------+------------+---------+------+--------------+--------------------------------------------------------------+ | 43481 | nen_mgla | localhost | mgla | Sleep | 40 | | | | 43564 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43592 | nen_mgla | localhost | mgla | Sleep | 20 | | | | 43593 | nen_mgla | localhost | mgla | Sleep | 14 | | | | 43596 | nen_mgla | localhost | mgla | Sleep | 16 | | | | 43606 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43609 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43618 | nen_mgla | localhost | mgla | Sleep | 16 | | | | 43628 | nen_mgla | localhost | mgla | Sleep | 12 | | | | 43630 | nen_mgla | localhost | mgla | Sleep | 14 | | | Please help me quickly
I want to modify the programming to work after the separation of the query and do not cause higher load
Support for Server said top - 12:32:50 up 9:31, 3 users, load average: 6.20, 5.97, 3.60 Tasks: 391 total, 2 running, 351 sleeping, 38 stopped, 0 zombie Cpu(s): 26.3%us, 4.9%sy, 0.1%ni, 65.4%id, 3.1%wa, 0.0%hi, 0.3%si, 0.0%st Mem: 8178308k total, 6552652k used, 1625656k free, 356888k buffers Swap: 2104504k total, 16k used, 2104488k free, 3189496k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 1893 mysql 10 -5 552m 212m 5052 S 92.7 2.7 45:30.11 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --log-error=/var/lib/mysql +-------+-------------+-----------+------------+---------+------+--------------+--------------------------------------------------------------+ | Id | User | Host | db | Command | Time | State | Info | +-------+-------------+-----------+------------+---------+------+--------------+--------------------------------------------------------------+ | 43481 | nen_mgla | localhost | mgla | Sleep | 40 | | | | 43564 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43592 | nen_mgla | localhost | mgla | Sleep | 20 | | | | 43593 | nen_mgla | localhost | mgla | Sleep | 14 | | | | 43596 | nen_mgla | localhost | mgla | Sleep | 16 | | | | 43606 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43609 | nen_mgla | localhost | mgla | Sleep | 17 | | | | 43618 | nen_mgla | localhost | mgla | Sleep | 16 | | | | 43628 | nen_mgla | localhost | mgla | Sleep | 12 | | | | 43630 | nen_mgla | localhost | mgla | Sleep | 14 | | |
you almost had 50k rows... high load is cause by thorough searching in each row, you cant just "select * from table" your database if you have huge numbers of data, this is either you limit your query, do a pagination if it doesnt bother you, select column1, column2, column3 from table where enable = 1 limit 0, 10 ++ : dont always use wildcard * be more specific this will save memory process.
including files in a loop can also be considered bad. Id don't know whats in hp.php, but consider including it outside of the while loop, or moving the contents of the file into the current script, if it needs to happen in the loop.
You will have to generate html using a script and serve this, otherwise there is no other way apart from pagination using LIMIT 0,10 at the end of the SQL query for example to solve this problem.