Please he lp in modifying the programming due to high load

Discussion in 'PHP' started by d3mk, May 19, 2010.

  1. #1
    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>&lt;? echo $row[a1]; ?&gt;</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">&nbsp;</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">&nbsp;<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">&nbsp; تم 
    				التحميل
    				<font color="#FF0000"><? echo $row[a7]; ?></font> مره</font></span></td>
    			</tr>
    		</table>
    		</td>
    		<td align="right" background="cats_044.gif" valign="top">
    		&nbsp;</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 :(
     
    d3mk, May 19, 2010 IP
  2. mike.judd

    mike.judd Greenhorn

    Messages:
    84
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    18
    #2
    what do you mean by high load? Can you be more specified what you need?
     
    mike.judd, May 19, 2010 IP
  3. d3mk

    d3mk Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I want to modify the programming to work after the separation of the query and do not cause higher load
     
    d3mk, May 19, 2010 IP
  4. d3mk

    d3mk Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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 | | |
     
    d3mk, May 19, 2010 IP
  5. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #5
    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.
     
    bartolay13, May 19, 2010 IP
  6. d3mk

    d3mk Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I hope to find someone that improves the query in the code :(
     
    d3mk, May 19, 2010 IP
  7. killaklown

    killaklown Well-Known Member

    Messages:
    2,666
    Likes Received:
    87
    Best Answers:
    0
    Trophy Points:
    165
    #7
    bartolay just said how to improve the query, dont expect people to rewrite your entire script..
     
    killaklown, May 19, 2010 IP
  8. friendishan

    friendishan Peon

    Messages:
    49
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    With high load...do you mean that mysql uses much of the resources?
     
    friendishan, May 19, 2010 IP
  9. d3mk

    d3mk Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    yes friendishan When you delete the script did not return the problem of high load
     
    d3mk, May 20, 2010 IP
  10. d3mk

    d3mk Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    up :( Is there a person solve the problem and modify the code
     
    d3mk, May 22, 2010 IP
  11. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #11
    up up up... i already answered your question..
     
    bartolay13, May 24, 2010 IP
  12. phpSiteMinder

    phpSiteMinder Peon

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    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.
     
    phpSiteMinder, May 24, 2010 IP
  13. metabinltd

    metabinltd Well-Known Member

    Messages:
    146
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    105
    #13
    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.
     
    metabinltd, May 24, 2010 IP