Huge RAM issue with PHP script

Discussion in 'PHP' started by subdivisions, Jan 17, 2011.

  1. #1
    Apparently something here is causing 2gb of RAM to be eaten. The site averages 40K page views per day.

    <?php
    $more['query'] = mysql_query("SELECT * FROM " . $prefix_db . "data ORDER BY RAND() LIMIT 20");
    $more['row']   = mysql_fetch_assoc($more['query']);
    ?>
    
    <ul>
    	<?php do { ?>
            <li>
            	<?php echo strip_tags($more['row']['text']); ?>
            </li>
        <?php } while ($more['row'] = mysql_fetch_assoc($more['query'])); ?>
    </ul>
    PHP:
    Is this a bad way of fetching MySQL rows? Is there a more RAM efficient way? Thanks!
     
    subdivisions, Jan 17, 2011 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    EricBruggema, Jan 18, 2011 IP
  3. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #3
    1. why you are capturing the mysql results into a array. use a variable. Arrays could cause lots of memory being used. Try this..

    $result = mysql_query("SELECT * FROM " . $prefix_db . "data ORDER BY RAND() LIMIT 20");
    $rows = mysql_fetch_assoc($result);

    2. Rand() infact may slow down the mysql, but only if you have huge number of records. if you have fewer records in your table, then it shouldnt be a problem.
     
    olddocks, Jan 18, 2011 IP