Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes) after ini_set

StackOverflow https://stackoverflow.com/questions/18888716

  •  29-06-2022
  •  | 
  •  

Вопрос

At first, I've already looked at this, this and this.

I've received the following error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 220 bytes)

I'm working with php 5.4and sql Anywhere 11.

The solution to this is according to this is putting ini_set('memory_set',-1); in my php-file, but after doing this I get another error:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes)

EDIT: my code is

<?php
    ini_set('memory_set',-1);
    $connect = sasql_connect("UID=username;PWD=pass");
    echo "Connection succeed";

    $result = sasql_query($connect, "SELECT * FROM table1, table2");

    if(!$result){
    echo "sasql_query failed";
    return 0;
    } else {
    echo "query completed successfully\n";
    sasql_result_all($result);
    }
    sasql_close($conn);
?>

I hope someone can help me.

SOLUTION: I've found the solution: I've added a WHERE (columnName1 = columnName2), split the result and it works again, relative fast!

<?php
    $connect = sasql_connect("UID=username;PWD=pass");
    if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };
    $results_page = 100;
    $start_from = ($page-1) * $results_page + 1;    
    $result = sasql_query($connect, "SELECT TOP $results_page START AT $start  * 
                    FROM table1, table2 WHERE (columnName1 = columnName2)");

    if(!$result){
    echo "sasql_query failed";
    return 0;
    } else {
    echo "query completed successfully\n";
    sasql_result_all($result);
    }
    sasql_close($conn);
?>

Ofcourse I add in my php-page a <a href="<?php echo $page -1; ?>">Previous</a> and a <a href="<?php echo $page + 1; ?>">Next</a>

Thanks to you all for the help!

Это было полезно?

Решение

You should use

ini_set("memory_limit",-1);

and not "memory_set". Also, look out for this: https://stackoverflow.com/a/5263981/2729140 (Suhosin extension has it's own memory limit setting).

If your script needs a lot of memory, then you should try and revise it. One thing to be aware of are unlimited SQL queries.

Your tables can have A LOT of records, so it's wise to always limit your queries. If you need to fetch all the records from the table, then you should do it by pages, using LIMIT ... OFFSET SQL constructs.

Другие советы

after many attempts I have identifed that if php-pecl-apc is installed the php config memory_limit can be reduced to 48M or less and it stops the Allowed memory size exhausted error.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top