Jump to content

Recommended Posts

Hi Guys,

I'm very new to php and having uploaded a small website for family on my friends vps.

 

Apparently, the vps has gone offline twice since uploading the site, due to memory leaks. My friend has asked me to check my code if it contained any leaks. The honest answer is that I don't really know.

 

The code is fairly simple, it just reads and prints stuff from a mysql database. Can anyone please review and put my mind at rest. Is it my code? or is he just picking on me?  :-)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Diwan's Website</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250" />
<link rel="stylesheet" type="text/css" media="screen, projection" href="menu.css" />
<link rel="stylesheet" type="text/css" media="screen, projection" href="style.css" />
<style type="text/css">
<!--

div.wrap1 .wrap2 {
/* only with left panel- background-image: url(img/bg1.gif); */
/* right and left panel - background-image: url(img/bg2.gif); */
/* only with right panel */ background-image: url(img/bg3.gif);
}

-->
</style>
</head>
<body>
<div class="wrap1">
  <div class="wrap2">
    <div class="logo"> Welcome to Diwan's
      <div class="slogan">Supplying the Taste from the East since 1998</div>
    </div>
    <div id="menu">
      <div class="menu">
        <ul>
         
   
          <li><span class="hlavny_"><a href="index.html">Home</a></span></li>
          <li><img src="img/divider2.png" alt="" /></li>

          <li><span class="hlavny_"><a href="shop.html" >Shop</a></span></li>
          <li><img src="img/divider2.png" alt="" /></li>


          <li><span class="left"></span><span class="hlavny"><a href="catering.html">Take Away & Catering</a></span><span class="right"></span></li>
          <li><img src="img/divider2.png" alt="" /></li>
          <li><span class="hlavny_"><a href="translation.html">Translation</a></span></li>
        </ul>
      </div>
      <div class="mainpanel" style="width:656px;">
      
   
     

      <div class="text_">
          <h1>Balti Dishes</a></h1>
          <div class="text"><br />  
            <br /> 
<?php


$user="diwans";
$password="9uXj0zJ";
$database="diwans";
$con =  mysql_connect(localhost,$user,$password);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db($database, $con);


$temp = mysql_query("SELECT COUNT(productid) as cnt FROM Product Where typeid<8");
$tempcnt = mysql_fetch_array($temp);

$i = $tempcnt['cnt'] + 1;

$result = mysql_query("SELECT * FROM Product Where typeid=8");



echo '<table>';
echo '<tr><td width = "500">Product
       </td><td width = "100">Price
      </td>' ;


while($row = mysql_fetch_array($result))
  {
  
  echo "<tr><td><x3>";
  echo $i++ .  ". " .  $row['name'] . " "; 
  echo "</x3><br />"; 
  $d = $row['description'];
  if ($d != "none")
{
  echo $row['description'];
  echo "<br />";
} 
  
  

echo "</td><td>";

  
  echo "&euro" . " " .  $row['price']; 
  echo "</td></tr>"; 
  
  }
echo '</table>'; 
mysql_close($con);
?> 





  </div>
           </a></h2>
        </div>
       
   </div>
      <div class="rightpanel">
        <div class="header">Our Dishes</div>
        <div class="inquiry"> <span class="divider" style="font-weight:bold;">Select by type</span>
        <span class="divider"><a href="starters.php"> Starters</a></span>
        <span class="divider"><a href="recommendation.php">Recommendations</a></span>
        <span class="divider"><a href="specials.php">Diwans Specialities</a></span>
        <span class="divider"><a href="tandoori.php">Tandoori Dishes</a></span>
        <span class="divider"><a href="curries.php">Traditional Curries</a></span>
        <span class="divider"><a href="veggiemain.php">Vegetarian Main Courses</a></span>
        <span class="divider"><a href="biryani.php">Biryani Dishes</a> </span>
        <span class="divider"><a href="balti.php">Balti Dishes</a></span>
        <span class="divider"><a href="vegiesd.php">Vegetable Side Dishes</a></span>
        <span class="divider"><a href="rice.php">Rice and Bread</a></span>
        <span class="divider"><a href="meals.php">Set Meals</a></span> <br />
        
        <span class="divider" style="font-weight:bold;">Select by preference</span>
        <span class="divider"><a href="vegie.php">Vegetarian</a> </span> 
        <span class="divider"><a href="nuts.php">Contains Nuts or Nut Products</a> </span> 
        <span class="divider"><a href="mhot.php">Medium Hot</a></span> 
        <span class="divider"><a href="fhot.php">Fairly Hot</a></span>
        <span class="divider"><a href="vhot.php">Very Hot</a> </span>  
        <br />   
        </div>
  
        <div class="header">Contact Us</div>
        <div class="text"> <strong>Diwans Grocery</strong><br />
          <br />
          Torhoutsesteenweg 89<br />
          <span class="divider">8400 OOSTENDE</span> Telephone: +32 59 518301<br />
          E-mail: [email protected] <br />
          <br />  
      </div>
    
        </div>       
        <br />
       </div>
       
   </div>
    <div class="info1">
      <div style="display:inline; float:left;">© 2008 <a href="http://www.diwans.be/">www.diwans.be</a></div>
      
    </div>
  </div>
</div>
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/201492-php-causing-memory-leaks/
Share on other sites

]hello,

 

well this is the log...

62339.762377] 1048576 pages of RAM
[62339.762400] 21254 reserved pages
[62339.762406] 4526 pages shared
[62339.762413] 0 pages swap cached
[62339.762417] Out of memory: kill process 4155 (apache2) score 25756 or a child
[62339.762436] Killed process 4155 (apache2)
[137469.125170] mysqld invoked oom-killer: gfp_mask=0x1201d2, order=0, oomkilladj=0
[137469.125184] Pid: 3037, comm: mysqld Not tainted 2.6.24-19-xen #1
[137469.125187]
[137469.125188] Call Trace:
[137469.125199]  [<ffffffff80275e26>] oom_kill_process+0xf6/0x110
[137469.125203]  [<ffffffff802762ae>] out_of_memory+0x19e/0x1e0
[137469.125208]  [<ffffffff80278bd9>] __alloc_pages+0x389/0x3c0
[137469.125213]  [<ffffffff8027af54>] __do_page_cache_readahead+0x104/0x260
[137469.125216]  [<ffffffff8027520e>] filemap_fault+0x2de/0x3e0
[137469.125220]  [<ffffffff80281f3a>] __do_fault+0x6a/0x5d0
[137469.125224]  [<ffffffff80287551>] handle_mm_fault+0x1d1/0xd60
[137469.125228]  [<ffffffff80229f63>] set_next_entity+0x23/0x50
[137469.125233]  [<ffffffff80473553>] do_page_fault+0x1f3/0x11e0
[137469.125239]  [<ffffffff8046f7e9>] thread_return+0x3a/0x481
[137469.125242]  [<ffffffff80471bf7>] error_exit+0x0/0x79
[137469.125245]
[137469.125247] Mem-info:
[137469.125249] DMA per-cpu:
[137469.125253] CPU    0: Hot: hi:    0, btch:   1 usd:   0   Cold: hi:    0, btch:   1 usd:   0
[137469.125256] DMA32 per-cpu:
[137469.125258] CPU    0: Hot: hi:  186, btch:  31 usd: 132   Cold: hi:   62, btch:  15 usd:  15
[137469.125262] Active:32199 inactive:728 dirty:0 writeback:0 unstable:0
[137469.125262]  free:4902 slab:2782 mapped:1 pagetables:1128 bounce:0
[137469.125267] DMA free:11540kB min:28kB low:32kB high:40kB active:0kB inactive:0kB present:16160kB pages_scanned:0 all_unreclaimable? yes
[137469.125270] lowmem_reserve[]: 0 4024 4024 4024
[137469.125275] DMA32 free:8068kB min:8100kB low:10124kB high:12148kB active:128796kB inactive:2912kB present:4120800kB pages_scanned:327624 all_unreclaimable? yes
[137469.125279] lowmem_reserve[]: 0 0 0 0
[137469.125282] DMA: 3*4kB 3*8kB 3*16kB 4*32kB 3*64kB 1*128kB 1*256kB 1*512kB 2*1024kB 0*2048kB 2*4096kB = 11540kB
[137469.125291] DMA32: 26*4kB 0*8kB 0*16kB 0*32kB 0*64kB 0*128kB 1*256kB 1*512kB 1*1024kB 1*2048kB 1*4096kB = 8040kB
[137469.125300] Swap cache: add 0, delete 0, find 0/0, race 0+0
[137469.125302] Free swap  = 0kB
[137469.125303] Total swap = 0kB
[137469.125304] Free swap:            0kB
[137469.156095] 1048576 pages of RAM
[137469.156113] 21254 reserved pages
[137469.156114] 5887 pages shared
[137469.156116] 0 pages swap cached
[137469.156120] Out of memory: kill process 12980 (apache2) score 50946 or a child
[137469.156138] Killed process 12980 (apache2)
[163175.581745] proxymap invoked oom-killer: gfp_mask=0x1201d2, order=0, oomkilladj=0
[163175.581757] Pid: 15818, comm: proxymap Not tainted 2.6.24-19-xen #1
[163175.581759]
[163175.581759] Call Trace:
[163175.581769]  [<ffffffff80275e26>] oom_kill_process+0xf6/0x110
[163175.581773]  [<ffffffff802762ae>] out_of_memory+0x19e/0x1e0
[163175.581777]  [<ffffffff80278bd9>] __alloc_pages+0x389/0x3c0
[163175.581781]  [<ffffffff8027af54>] __do_page_cache_readahead+0x104/0x260
[163175.581784]  [<ffffffff8027520e>] filemap_fault+0x2de/0x3e0
[163175.581788]  [<ffffffff80281f3a>] __do_fault+0x6a/0x5d0
[163175.581791]  [<ffffffff80287551>] handle_mm_fault+0x1d1/0xd60
[163175.581794]  [<ffffffff8028ae2a>] vma_link+0xca/0x140
[163175.581799]  [<ffffffff80473553>] do_page_fault+0x1f3/0x11e0
[163175.581802]  [<ffffffff8028c028>] do_mmap_pgoff+0x3a8/0x3d0
[163175.581808]  [<ffffffff8033a122>] __up_write+0x22/0x130
[163175.581811]  [<ffffffff80471bf7>] error_exit+0x0/0x79
[163175.581814]
[163175.581815] Mem-info:
[163175.581817] DMA per-cpu:
[163175.581825] CPU    0: Hot: hi:    0, btch:   1 usd:   0   Cold: hi:    0, btch:   1 usd:   0
[163175.581827] DMA32 per-cpu:
[163175.581830] CPU    0: Hot: hi:  186, btch:  31 usd: 137   Cold: hi:   62, btch:  15 usd:  45
[163175.581834] Active:32178 inactive:825 dirty:0 writeback:0 unstable:0
[163175.581835]  free:4887 slab:2778 mapped:1 pagetables:1049 bounce:0
[163175.581839] DMA free:11540kB min:28kB low:32kB high:40kB active:0kB inactive:0kB present:16160kB pages_scanned:0 all_unreclaimable? yes
[163175.581841] lowmem_reserve[]: 0 4024 4024 4024
[163175.581846] DMA32 free:8008kB min:8100kB low:10124kB high:12148kB active:128712kB inactive:3300kB present:4120800kB pages_scanned:235994 all_unreclaimable? yes
[163175.581850] lowmem_reserve[]: 0 0 0 0
[163175.581853] DMA: 3*4kB 3*8kB 3*16kB 4*32kB 3*64kB 1*128kB 1*256kB 1*512kB 2*1024kB 0*2048kB 2*4096kB = 11540kB
[163175.581861] DMA32: 14*4kB 0*8kB 1*16kB 0*32kB 0*64kB 0*128kB 1*256kB 1*512kB 1*1024kB 1*2048kB 1*4096kB = 8008kB
[163175.581871] Swap cache: add 0, delete 0, find 0/0, race 0+0
[163175.581872] Free swap  = 0kB
[163175.581873] Total swap = 0kB
[163175.581874] Free swap:            0kB
[163175.606015] 1048576 pages of RAM
[163175.606021] 21254 reserved pages
[163175.606023] 4496 pages shared
[163175.606024] 0 pages swap cached
[163175.606027] Out of memory: kill process 15726 (apache2) score 51018 or a child
[163175.606041] Killed process 15726 (apache2)
[227591.865546] mysqld invoked oom-killer: gfp_mask=0x1201d2, order=0, oomkilladj=0
[227591.865563] Pid: 3036, comm: mysqld Not tainted 2.6.24-19-xen #1
[227591.865565]
[227591.865566] Call Trace:
[227591.865577]  [<ffffffff80275e26>] oom_kill_process+0xf6/0x110
[227591.865581]  [<ffffffff802762ae>] out_of_memory+0x19e/0x1e0
[227591.865587]  [<ffffffff80278bd9>] __alloc_pages+0x389/0x3c0
[227591.865591]  [<ffffffff8027af54>] __do_page_cache_readahead+0x104/0x260
[227591.865594]  [<ffffffff8027520e>] filemap_fault+0x2de/0x3e0
[227591.865598]  [<ffffffff80281f3a>] __do_fault+0x6a/0x5d0
[227591.865600]  [<ffffffff80287551>] handle_mm_fault+0x1d1/0xd60
[227591.865605]  [<ffffffff80473553>] do_page_fault+0x1f3/0x11e0
[227591.865609]  [<ffffffff8046f7e9>] thread_return+0x3a/0x481
[227591.865613]  [<ffffffff8043d710>] udp_poll+0x0/0x160
[227591.865616]  [<ffffffff80471bf7>] error_exit+0x0/0x79
[227591.865618]
[227591.865619] Mem-info:
[227591.865621] DMA per-cpu:
[227591.865623] CPU    0: Hot: hi:    0, btch:   1 usd:   0   Cold: hi:    0, btch:   1 usd:   0
[227591.865626] DMA32 per-cpu:
[227591.865628] CPU    0: Hot: hi:  186, btch:  31 usd: 183   Cold: hi:   62, btch:  15 usd:  20
[227591.865636] Active:32132 inactive:936 dirty:0 writeback:0 unstable:0
[227591.865637]  free:4907 slab:2755 mapped:1 pagetables:1052 bounce:0
[227591.865640] DMA free:11540kB min:28kB low:32kB high:40kB active:0kB inactive:0kB present:16160kB pages_scanned:0 all_unreclaimable? yes
[227591.865643] lowmem_reserve[]: 0 4024 4024 4024
[227591.865648] DMA32 free:8088kB min:8100kB low:10124kB high:12148kB active:128528kB inactive:3744kB present:4120800kB pages_scanned:228330 all_unreclaimable? yes
[227591.865651] lowmem_reserve[]: 0 0 0 0
[227591.865654] DMA: 3*4kB 3*8kB 3*16kB 4*32kB 3*64kB 1*128kB 1*256kB 1*512kB 2*1024kB 0*2048kB 2*4096kB = 11540kB
[227591.865663] DMA32: 35*4kB 3*8kB 1*16kB 0*32kB 1*64kB 1*128kB 0*256kB 1*512kB 1*1024kB 1*2048kB 1*4096kB = 8052kB
[227591.865672] Swap cache: add 0, delete 0, find 0/0, race 0+0
[227591.865673] Free swap  = 0kB
[227591.865675] Total swap = 0kB
[227591.865676] Free swap:            0kB
[227591.890898] 1048576 pages of RAM
[227591.890909] 21254 reserved pages
[227591.890911] 4581 pages shared
[227591.890913] 0 pages swap cached
[227591.890916] Out of memory: kill process 19607 (apache2) score 51146 or a child
[227591.890930] Killed process 19607 (apache2)
[285212.411565] mysqld invoked oom-killer: gfp_mask=0x1201d2, order=0, oomkilladj=0
[285212.411580] Pid: 3036, comm: mysqld Not tainted 2.6.24-19-xen #1
[285212.411583]
[285212.411584] Call Trace:
[285212.411596]  [<ffffffff80275e26>] oom_kill_process+0xf6/0x110
[285212.411600]  [<ffffffff802762ae>] out_of_memory+0x19e/0x1e0
[285212.411605]  [<ffffffff80278bd9>] __alloc_pages+0x389/0x3c0
[285212.411610]  [<ffffffff8027af54>] __do_page_cache_readahead+0x104/0x260
[285212.411618]  [<ffffffff8027520e>] filemap_fault+0x2de/0x3e0
[285212.411623]  [<ffffffff80281f3a>] __do_fault+0x6a/0x5d0
[285212.411626]  [<ffffffff80287551>] handle_mm_fault+0x1d1/0xd60
[285212.411631]  [<ffffffff80229f63>] set_next_entity+0x23/0x50
[285212.411636]  [<ffffffff80473553>] do_page_fault+0x1f3/0x11e0
[285212.411641]  [<ffffffff8046f7e9>] thread_return+0x3a/0x481
[285212.411645]  [<ffffffff80471bf7>] error_exit+0x0/0x79
[285212.411647]
[285212.411649] Mem-info:
[285212.411651] DMA per-cpu:
[285212.411654] CPU    0: Hot: hi:    0, btch:   1 usd:   0   Cold: hi:    0, btch:   1 usd:   0
[285212.411657] DMA32 per-cpu:
[285212.411659] CPU    0: Hot: hi:  186, btch:  31 usd: 135   Cold: hi:   62, btch:  15 usd:  15
[285212.411663] Active:31898 inactive:1124 dirty:0 writeback:0 unstable:0
[285212.411664]  free:4902 slab:2884 mapped:20 pagetables:1028 bounce:0
[285212.411668] DMA free:11540kB min:28kB low:32kB high:40kB active:0kB inactive:0kB present:16160kB pages_scanned:0 all_unreclaimable? yes
[285212.411670] lowmem_reserve[]: 0 4024 4024 4024
[285212.411675] DMA32 free:8068kB min:8100kB low:10124kB high:12148kB active:127592kB inactive:4496kB present:4120800kB pages_scanned:229123 all_unreclaimable? yes
[285212.411678] lowmem_reserve[]: 0 0 0 0
[285212.411682] DMA: 3*4kB 3*8kB 3*16kB 4*32kB 3*64kB 1*128kB 1*256kB 1*512kB 2*1024kB 0*2048kB 2*4096kB = 11540kB
[285212.411691] DMA32: 17*4kB 0*8kB 1*16kB 0*32kB 0*64kB 0*128kB 1*256kB 1*512kB 1*1024kB 1*2048kB 1*4096kB = 8020kB
[285212.411700] Swap cache: add 0, delete 0, find 0/0, race 0+0
[285212.411702] Free swap  = 0kB
[285212.411703] Total swap = 0kB
[285212.411704] Free swap:            0kB
[285212.446171] 1048576 pages of RAM
[285212.446180] 21254 reserved pages
[285212.446182] 4492 pages shared
[285212.446184] 0 pages swap cached
[285212.446187] Out of memory: kill process 24471 (apache2) score 50269 or a child
[285212.446206] Killed process 24471 (apache2)

 

I must say the memory leaks apparently occur at random. it works when accessing just fine.

 

My friend assumes it's my code causing problems, since the problems occurred twice since uploading.

 

If you guys are convinced the code is fine, i'll relay the statements to my friend, and he can investigate the matter further

 

as for

That code specificly shouldn't cause any memory problems for the server although I am a little baffled by your SQL.  could you explain it please?

 

Well the SQL basically is what it is. I query for a product where it's product type has a certain ID. The pages are static, for instance when loading balti.php I query using typeID=8 (for balti) or typeID=1 for starters. This is the balti page. (see http://diwans.tk/balti.php)

 

I am aware that this isn't the 'right' way to do, but it works and i couldn't be bothered writing joins as it works ...

 

thanks again

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.