Results 1 to 4 of 4

Thread: php memory

  1. #1
    Join Date
    May 2006
    Location
    New York City
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default php memory

    So I have this really big, presumably memory intensive script. It always worked before, but now it's giving me this error:

    Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 132877 bytes) in [pathtofile] on line 212

    There's nothing spectacular about that particular line; i think it may just be that that's where it was when it ran out of memory. Anyhow, it's a form script with itself as the action, and it interacts heavily with mysql. I've tried using mysql_free_result(), but that doesn't seem to help so much. Any other suggestions for freeing up memory space?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Process each row at a time rather than trying to fit the whole thing into memory at once? I'd have to see the code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Location
    New York City
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I believe it already does this, which is the confusing part. It's a really big code, but here's a representative snippet:

    Code:
                   $query = "SELECT aff, url, des, thumb FROM $table WHERE id = '$key'";
                   $result = mysql_query($query);
                   $exists = mysql_num_rows($result);
                   $dbrow = mysql_fetch_row($result);
                   mysql_free_result($result);
    
                   if ($exists) {
    
                        $dbrow = implode("|", $dbrow);
                        $postrow = "$aff|$url|$des|$thumb";
    
                        if ($dbrow == $postrow) {
                             $message[] = "";
                        } else if (trim($postrow, "|") == "") {
                             $query_2 = "DELETE FROM $table WHERE $table.id = $key LIMIT 1";
                        } else {
                             $url_id = array_search($url, $url_set);
                             if (($url_id == $key) || ($url_id === false)) {
                                  $query_2 = "UPDATE $table SET url = '$url', des = '$des', thumb = '$thumb', aff='$aff' WHERE id = '$key'";
                             } else {
                                  $message[] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <small>Error: duplicate url -- $url </small><br/>\n";
                             }
                        }
    
                   } else if (!$exists) {
    
                        if (trim($value, "|") != "") {
                             if (in_array($url, $url_set)) {
                                  $message[] = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <small>Error: duplicate url -- $url </small><br/>\n";
                             } else {
                                  $query_2 = "INSERT INTO $table (id, star, aff, url, base_url, des, thumb) VALUES ('$key', '$passthru', '$aff', '$url', '$base_url', '$des', '$thumb')";
                             }
                        }
                   }
                   $result_2 = mysql_query($query_2);
                   if ($result_2) {
                        $message[] = "Successfully updated the database<br/>\n";
                        mysql_free_result($result_2);
                   } else {
                        $message[] = "Error updating $table: " . mysql_error() . "<br/>\n";
                   }
                   unset($aff); unset($url); unset($des); unset($thumb);
    this is, as you can imagine, part of a foreach which loops about a hundred times.

    I had connected to mysql by way of mysql_pconnect() until about four or five hours ago when i changed it to mysql_connect(), thinking that this would free up some memory. Should i change it back?

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not the relevant part, I'm afraid.

    Whether you use connect() or pconnect() here doesn't make a lot of difference.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •