开发者

memory problems mysql

开发者 https://www.devze.com 2023-02-19 01:27 出处:网络
I\'m having problems updating a mysql database. I want to run this script on a ~800,000 row database but my memory runs out after 5 rows so some how I need to automatically update this mysql query by

I'm having problems updating a mysql database. I want to run this script on a ~800,000 row database but my memory runs out after 5 rows so some how I need to automatically update this mysql query by adding +5 to the LIMIT.

I want to use a redirect or reset the memory somehow..

<?php

    include(dirname(__FILE__) .'/include/simple_html_dom.php');

    mysql_connect('localhost', '', '');
    mysql_select_db('');

    $result = mysql_query("SELECT gamertag FROM gamertags LIMIT 0, 5 ");
        while ($row = mysql_fetch_assoc($result)) {
            $gamertag = $row['gamertag'];

            //pages to pull stats from
            $site_url = 'http://www.bungie.net';
            $stats_page = 'http://www.bungie.net/stats/reach/default.aspx?player=';

            //create dom
            $html = new simple_html_dom();
            $html->load_file($stats_page . urlencode(strtolower($gamertag)));

            //pull nameplate emblem url, ****if it exist****
            $nameplate_emblem_el = $html->find("#ctl00_mainContent_identityBar_namePlateImg");
            if (!$nameplate_emblem_el){
                $nameplate_emblem = 'No nameplate emblem!';
            }
            else{
                //only if #ctl00_mainContent_identityBar_namePlateImg is found
                $nameplate_emblem = htmlspecialchars_decode($nameplate_emblem_el[0]->attr['src开发者_JAVA百科']);
                $nameplate_emblem = $site_url . $nameplate_emblem;
            }   

            mysql_query("INSERT IGNORE INTO star SET gamertag = '".$gamertag."',nameplate = '".$nameplate_emblem."'");
        }

?>


800.000 is a large number, not sure if it´s gonna happen, but from a comments on php manual: "unset() does just what it's name says - unset a variable. It does not force immediate memory freeing. PHP's garbage collector will do it when it see fits - by intention as soon, as those CPU cycles aren't needed anyway, or as late as before the script would run out of memory, whatever occurs first.

If you are doing $whatever = null; then you are rewriting variable's data. You might get memory freed / shrunk faster, but it may steal CPU cycles from the code that truly needs them sooner, resulting in a longer overall execution time."

source:http://php.net/manual/en/function.unset.php

So, try to unset/set to null the variables after each time the loop runs.


I'm guessing that you hit your php memory limit, and not the machines. If so, you can edit php.ini (typically /etc/php5/apache2/php.ini) to give more memory to php. Look for "memory_limit = X" where X is something like 256M

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号