Web Analytics Made Easy -
StatCounter Out of Memory Error o simple script - CodingForum

Announcement

Collapse
No announcement yet.

Out of Memory Error o simple script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Out of Memory Error o simple script

    Hi,
    I am using a for loop to append short names from a file to inputted variables.
    The names are only about 20 characters long and a maximum of 500 of them
    However my for loop limits it to only 300

    ... so why the out of memory error ?

    Here is my script:

    SORRY ABOUT the echos but I was trying to see the problem myself.

    I don't get any output

    only this:
    Fatal error: Allowed memory size of 134217728 bytes exhausted

    PHP Code:
    $cities "/home/com567b/projects/cities.txt";
        
    $thekeys = array();
        
    $outfile $pro_path.$Db_out_file;
        
    $all_cities file_get_contents($cities);
        
    $all_cities explode(PHP_EOL$all_cities); 
        
    // $find = ',"';
        
    for ( $i 0$i 10; ++$i) {
            
    // $value = str_replace('"','',$value);
            
    $thekeys[] = $Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 1 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = $Db_keyword1.' store in '.$all_cities[$i]; echo "Added $i , 1, 2 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = $Db_keyword1.' shop in '.$all_cities[$i]; echo "Added $i , 1, 3 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = $Db_keyword1.' for sale in '.$all_cities[$i]; echo "Added $i , 1, 4 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'best '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 5 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'cheap '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 6 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'discount '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 7 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'sales '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 8 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'where to get '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 9 : $Db_keyword1 in $all_cities[$i]<br>";
            
    $thekeys[] = 'where to buy '.$Db_keyword1.' in '.$all_cities[$i]; echo "Added $i , 1, 10 : $Db_keyword1 in $all_cities[$i]<br>";
            if(
    $Db_keyword2 != ''){
                
    $thekeys[] = $Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 1 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword2.' store in '.$all_cities[$i]; echo "Added $i , 2, 2 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword2.' shop in '.$all_cities[$i]; echo "Added $i , 2, 3 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword2.' for sale in '.$all_cities[$i]; echo "Added $i , 2, 4 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'best '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 5 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'cheap '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 6 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'discount '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 7 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'sales '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 8 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'where to get '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 9 : $Db_keyword2 in $all_cities[$i]<br>";
                
    $thekeys[] = 'where to buy '.$Db_keyword2.' in '.$all_cities[$i]; echo "Added $i , 2, 10 : $Db_keyword2 in $all_cities[$i]<br>";
                }
            if(
    $Db_keyword3 != ''){
                
    $thekeys[] = $Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 1 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword3.' store in '.$all_cities[$i]; echo "Added $i , 3, 2 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword3.' shop in '.$all_cities[$i]; echo "Added $i , 3, 3 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = $Db_keyword3.' for sale in '.$all_cities[$i]; echo "Added $i , 3, 4 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'best '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 5 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'cheap '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 6 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'discount '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 7 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'sales '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 8 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'where to get '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 9 : $Db_keyword3 in $all_cities[$i]<br>";
                
    $thekeys[] = 'where to buy '.$Db_keyword3.' in '.$all_cities[$i]; echo "Added $i , 3, 10: $Db_keyword3 in $all_cities[$i]<br>";
                }
    }    

        
    $thekeys implode(PHP_EOL,$thekeys);
        
    file_put_contents($outfile$thekeys); 
    Can you see the problem ?

    Thanks.
    David.
    Last edited by jeddi; Sep 20, 2016, 12:43 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    You probably meant

    The statement
    PHP Code:
       // $find = ',"';
        
    for ( $i 0$i 10; ++$i) { 
    will execute forever as the condition $i = 10, will always be true and $i will always be stucked at 10, thereby eating up memory.

    You probably want

    PHP Code:
        // $find = ',"';
        
    for ( $i 0$i 10; ++$i) { 

    Comment


    • #3
      Of course !!

      Thank you
      If you want to attract and keep more clients, then offer great customer support.

      Support-Focus.com. automates the process and gives you a trust seal to place on your website.
      I recommend that you at least take the 30 day free trial.

      Comment

      Working...
      X