php 致命错误:ini_set 后允许的内存大小为 134217728 字节(尝试分配 3 个字节)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18888716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes) after ini_set
提问by Kenny
At first, I've already looked at this, thisand this.
I've received the following error:
我收到以下错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 220 bytes)
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 220 bytes)
I'm working with php 5.4
and sql Anywhere 11
.
我正在与php 5.4
和一起工作sql Anywhere 11
。
The solution to this is according to thisis putting ini_set('memory_set',-1);
in my php-file
, but after doing this I get another error:
对此的解决方案是根据this放入ini_set('memory_set',-1);
my php-file
,但在执行此操作后,我收到另一个错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 3 bytes)
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!
解决方案:我找到了解决方案:我添加了一个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);
?>
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>
当然,我添加了我的php-page
a<a href="<?php echo $page -1; ?>">Previous</a>
和 a<a href="<?php echo $page + 1; ?>">Next</a>
Thanks to you all for the help!
感谢大家的帮助!
回答by sp-niemand
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).
而不是“memory_set”。另外,请注意:https://stackoverflow.com/a/5263981/2729140(Suhosin 扩展有自己的内存限制设置)。
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.
如果您的脚本需要大量内存,那么您应该尝试修改它。需要注意的一件事是无限制的 SQL 查询。
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.
你的表可以有很多记录,所以总是限制你的查询是明智的。如果您需要从表中获取所有记录,那么您应该使用LIMIT ... OFFSET
SQL 结构按页来完成。
回答by shaun callender
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.
经过多次尝试,我发现如果安装了 php-pecl-apc,则 php config memory_limit 可以减少到 48M 或更少,并且它会停止允许的内存大小耗尽错误。