jjzjj

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

coder 2024-04-09 原文

一开始,我已经看了this , thisthis .

我收到以下错误:

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

我正在使用 php 5.4sql Anywhere 11 .

这个问题的解决方案是根据this正在放ini_set('memory_set',-1);在我的 php-file ,但在这样做之后我得到另一个错误:

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

编辑:我的代码是

<?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);
?>

我希望有人能帮助我。

解决方案: 我找到了解决方案:我添加了一个 WHERE (columnName1 = columnName2) ,拆分结果,它再次工作,速度相对较快!

<?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);
?>

当然我会添加我的 php-page一个<a href="<?php echo $page -1; ?>">Previous</a>和一个 <a href="<?php echo $page + 1; ?>">Next</a>

感谢大家的帮助!

最佳答案

你应该使用

ini_set("memory_limit",-1);

而不是“memory_set”。另外,请注意:https://stackoverflow.com/a/5263981/2729140 (Suhosin 扩展有它自己的内存限制设置)。

如果您的脚本需要大量内存,那么您应该尝试修改它。需要注意的一件事是无限制的 SQL 查询。

您的表可能有很多记录,因此始终限制您的查询是明智的。如果您需要从表中获取所有记录,那么您应该使用 LIMIT ... OFFSET SQL 结构按页执行。

关于php - fatal error : Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes) after ini_set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18888716/

有关php - fatal error : Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes) after ini_set的更多相关文章

随机推荐