Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:51:10+00:00 2026-06-12T03:51:10+00:00

could you please help me to find what cause this process to reach 500MB

  • 0

could you please help me to find what cause this process to reach 500MB of memory usage.
It is basically an html page downloader.
Despite the fact that the process is stable (and do not exceed that limit), it’ meant to use on low performing machine and I’m not satisfied.
The size of the mysql table ‘Sites’ is 170MB.
following the script code.
Thanks in advance.

function start() {
try {
    global $log;
    $db = getConnection();
    Zend_Db_Table::setDefaultAdapter($db);
    $log->logInfo("logger start");
    while (1) {
        $sitesTable = new Zend_Db_Table('Sites');
        $rowset = $sitesTable->fetchAll();
        foreach ($rowset as $row) {
            if (time() >= (strtotime($row->lastUpdate) + $row->pollingHours * 60 * 60)) {
                db_updateHtml($row);
            }
        }
    }
} catch (Exception $e) {
    global $log;
    $log->logError($e->getMessage());
}
}

    function db_updateHtml($siteRecord) {
        try {
            if ($siteRecord instanceof Zend_Db_Table_Row) {
                $rowwithConnection = $siteRecord;
                $url = $siteRecord->url;

                $idSite = $siteRecord->idSite;
                $crawler = new Crawler();
                $sitesTable = new Zend_Db_Table('Sites');
                //$rowwithConnection = $sitesTable->fetchRow(
                  //      $sitesTable->select()->where('idSite = ?', $idSite));
                $newHtml = HtmlDbEncode($crawler->get_web_page($url));


                if (strlen($newHtml) < 10) {
                    global $log;
                    $log->logError("Download failed for: url: $url \t idsite: $idSite ");
                }
                if ($rowwithConnection->isChecked != 0) {
                    $rowwithConnection->oldHtml = $rowwithConnection->newHtml;
                    $rowwithConnection->isChecked = 0;
                }
                $rowwithConnection->newHtml = $crawler->get_web_page($url);
                $rowwithConnection->lastUpdate = date("Y-m-d H:i:s");
                //$rowwithConnection->diffHtml = getDiff($rowwithConnection->oldHtml, $rowwithConnection->newHtml, false, $rowwithConnection->minLengthChange);
                $rowwithConnection->diffHtml = getDiffFromRecord($rowwithConnection, false, $rowwithConnection->minLengthChange);
                /* if (strlen($rowwithConnection->diffHtml) > 30) {
                  $rowwithConnection->lastChanged = $rowwithConnection->lastUpdate;
                  } */
                $rowwithConnection->save();
            } else {
                $log->logCrit("siteRecord is uninitialized");
            }
        } catch (Exception $e) {
            global $log;
            $log->logError($e->getMessage());
        }
    }

    function getDiffFromRecord($row, $force = false, $minLengthChange = 100) {
        if ($row instanceof Zend_Db_Table_Row) {
            require_once '/var/www/diff/library/finediff.php';
            include_once '/var/www/diff/library/Text/Diff.php';
            $diff = new AndreaDiff();
            $differences = $diff->getDiff($row->oldHtml, $row->newHtml);
            if ($diff->isChanged($minLengthChange) || $force) {
                $row->lastChanged = $row->lastUpdate;
                $row->isChecked = false;
                return ($differences);
            }
        }
        return null;
    }

    function getConnection() {
        try {
            $pdoParams = array(
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
            );
            $db = new Zend_Db_Adapter_Pdo_Mysql(array(
                        'host' => '127.0.0.1',
                        'username' => 'root',
                        'password' => 'administrator',
                        'dbname' => 'diff',
                        'driver_options' => $pdoParams
                    ));
            return $db;
        } catch (Exception $e) {
            global $log;
            $log->logError($e->getMessage());
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:51:11+00:00Added an answer on June 12, 2026 at 3:51 am

    1) Try use fetch method, not fetchAll:

    foreach($sitesTable->fetch() as $row){
       //...
    }
    

    2) try to unset all variables which store html code (if you save it in memory), at last iteration i suppose variable $rowwithConnection will have html code inside.

    When i want profile php application i use xhprof it will save you a LOT of time. Good Luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could guys please help me find what causes memory leak ? It drives me
Could you please help me find out the time complexity of the Fleury' algorithm
Could you please help me out to find the correct deceleration rate for the
I have one intresting requirement to achieve. could you please help? Please find the
Could you please help me converting this c++ code into python: I am trying
Could someone please help me to convert this String into a Map ... String
Could someone please help explain why I can't get this to work? I properly
yes, this is a homework-type question but could you please help me out? In
Could someone please help me find out why my attempt to bind Collection to
I wonder whether someone could help me please. I've been looking through this, and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.