4

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!

Community
  • 1
  • 1
Kenny
  • 177
  • 2
  • 3
  • 14
  • 2
    Make sure you don't have an infinite loop or a never ending recursive function. – Virus721 Sep 19 '13 at 07:53
  • @Virus721 I added my code and I guess I don't do anything wrong in this? – Kenny Sep 19 '13 at 08:28
  • I don't know what is sasql, but i don't think it comes from here, unless you're extracting a large amount of data. – Virus721 Sep 19 '13 at 08:35
  • That was the problem, I'm extracting a lot of amount, that's the reason I needed to expand the memory. Thanks anyway for your help – Kenny Sep 19 '13 at 08:43

2 Answers2

17

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.

Community
  • 1
  • 1
sp-niemand
  • 225
  • 4
  • 10
  • I used also a part of your answer, the `SQL Anywhere 11` is build this way: `SELECT TOP 20 START AT 1 * FROM table1, table2`. Thanks for your help – Kenny Sep 19 '13 at 11:53
0

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.