Reputation:
i am running an program that increases the memory while executing each time... i am getting the links from the database and parsing for contents...
<?php
include "aa.php";
$ex="all_link";
$cd="crawled_link";
$sql="SELECT * FROM $ex";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$i=1;
$j=1;
$temp=0;
while($count > 0)
{
$sql="SELECT * FROM $ex where num='$i'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
$a=$rows['link'];
$sql="SELECT * FROM $cd where link='$a'";
$result1=mysql_query($sql);
$rows1=mysql_num_rows($result1);
flush();
if(!$rows1)
{
$cdurl=trim($rows['link']);
start_scan($cdurl);
}
else
{
}
$sql="SELECT * FROM $ex";
$result=mysql_query($sql);
$temp=mysql_num_rows($result);
$count=$temp-$i;
$i++;
flush();
}
mysql_close();
while it execute first time the memory is 4 MB and after that it increases up 25o and greater is there is any way to get out of it....
Upvotes: 1
Views: 173
Reputation: 382881
Memory is freed up:
Situation 1 occurs when you use unset()
, mysql_free_result()
, or other resource-destroying functions that explicitly clear up after your variables. Situation 2 clears up resources implicitly - any variable that leaves scope, i.e. is no longer applicable, gets cleared up for you. Finally, situation 3 frees up all script-related resources implicitly.
Note that you can get memory usage with memory_get_usage
. Once you free up some resources with unset
, etc you can check out the difference, here is an example:
echo memory_get_usage() . <br />;
unset(......);
unset(......);
unset(......);
echo memory_get_usage();
Listen to all errors, big and small
Always set your PHP error level to the most verbose level, E_ALL. All too often people don't realise that PHP is outputting various complaints about variables not being set, etc, which you can just do away with entirely by cleaning up your code. While you are editing your php.ini file, it would also help to disable all the extensions you don't use - they are just chewing up memory otherwise.
Upvotes: 2