- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在编写一个 codeigniter 应用程序,在执行查询时遇到以下 fatal error 。
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /var/www/html/cryd/_zcore/core/Loader.php on line 262
我可以增加允许的内存大小,但问题似乎更严重,如果是内存泄漏,我只会给 php 更多内存来玩。查询甚至没有那么密集,它只返回一行数据。
这是我的 Controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Invest_webhook extends CI_Controller {
private $web_msg = null;
private $proceed = 1;
private $data = null;
private $receive = null;
private $complete = 0;
private $member = null;
private function loadPage($page,$data=null){
$data = array_merge($data,$this->lang->language);
$this->parser->parse('dashboard/header',$data);
$this->parser->parse('dashboard/'.$page);
$this->parser->parse('dashboard/footer');
}
public function webhook(){
echo memory_get_peak_usage()."<br/>";
//$update = file_get_contents("php://input");
//$update = json_decode($update,true);
$update = array(
'notification_id' => '57233292b6a3d133e9c83822',
'delivery_attempt' => 1,
'type' => 'address',
'data' => Array(
'network' => "BTCTEST",
'address' => '2N1jfZt8Uc721FAWNjdVpQZjfTxeG271RKy',
'balance_change' => 1.00000000,
'amount_sent' => 0.00000000,
'amount_received' => 1.00000000,
'txid' => '',
'confirmations' => 4,
'is_green' => false
),
'created_at' => 1497176944
);
$data = $this->get_investment_data($update['data']['address']);
if(!$data){
die('This address does not exist');
}
$this->data = $data[0];
$this->member = $this->get_member_data($this->data['tid']);
//Start the process to verify transaction and credit investment
$this->verify_investment();
$this->update_investment();
//$parameter = $this->web_msg;
//include APPPATH."libraries/telegrambotv2.php";
//$bot = new Telegram('331263599:AAEpHNAdyN1X5TenBk_QkJdt7xfwzDI6YeQ','bot');
echo $this->web_msg."<br/>";
}
private function verify_investment(){
include APPPATH."/libraries/BlockIo.php";
$this->load->config('block');
$block = new BlockIo($this->config->item('api_token'),$this->config->item('api_secret'));
$address = ($this->data['address']);
$receive = $block->get_address_balance(array('addresses' => $address));
$receive = $receive->data->available_balance;
$expect = $this->data['inv'];
settype($receive,'float');
settype($expect,'float');
echo '<br/>'.$receive."<br/>".$expect."<br/>";
if($receive == $expect){
$this->receive = $receive;
return true;
}
$this->proceed = 0;
$this->web_msg = 'inv_mismatch';
return false;
}
private function get_member_data($tid){
$this->load->model('invest_model','invest');
return $this->get_member_data($tid);
}
private function update_investment(){
if(!$this->proceed){
return;
}
$this->load->model('invest_model','invest');
$einv = $this->member['inv'];
settype($einv,'float');
$new_inv = $einv + $this->receive;
$this->member['inv'] = $new_inv;
$this->member['last_inv'] = 'NOW()';
$this->data['confirmed'] = 1;
if($this->invest->update_investment($this->data,$this->member)){
$this->web_msg = 'inv_complete';
$this->complete = 1;
return true;
} else {
$this->proceed = 0;
$this->web_msg = 'inv_unx_err';
return false;
}
}
private function get_investment_data($address){
$this->load->model('invest_model','invest');
return $this->invest->investment_data($address);
}
private function log($text){
$file = fopen(APPPATH."/logs/investments/log.log",'a');
fwrite($file,$text);
fwrite($file,"\n");
fclose($file);
}
}
这是我的模型
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Invest_model extends CI_Model {
public function __construct(){
parent::__construct();
}
public function investment_data($address){
$this->db->where('address',$address);
$this->db->where('confirmed',0);
$f = $this->db->get('investments');
return $f->result_array();
}
public function current_investment($tid){
$this->db->select('inv');
$this->db->where('tid',$tid);
$f = $this->db->get('users');
$f = $f->row_array();
return $f;
}
public function get_member_data($tid){
echo "<hr/>";
echo memory_get_peak_usage()."<br/>";
$this->db->where('tid',$tid);
echo memory_get_peak_usage()."<br/>";
$f = $this->db->get('users');
echo memory_get_peak_usage()."<br/>";
return $f->row_array();
}
public function update_investment($inv,$member){
$this->db->trans_begin();
$this->db->set($inv);
$this->db->where('address',$inv['address']);
$this->db->update('investments');
$this->db->set($member);
$this->db->where('tid',$member['tid']);
$this->db->update('users');
if($this->db->trans_status() === FALSE){
$this->db->trans_rollback();
return false;
} else {
$this->db->trans_commit();
return true;
}
}
}
我不知道我可以在哪里进一步优化它,它非常简单和直接,如果它在我的逻辑方法中有问题,希望比我更好的头脑能够发现并进一步指导我。
提前致谢。
最佳答案
您的代码看起来不错。检查是否重复调用了某些函数。
你可以使用
ini_set('memory_limit', '-1');
作为临时解决方案。或者只是增加 memory_limit
检查你的 php.ini
文件。如果是下面的形式,
memory_limit=8G
以 MB 的形式更改它
memory_limit=8192M
你也可以在你的代码中这样做
ini_set('memory_limit', '8192M');
关于PHP fatal error 允许内存大小耗尽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45008068/
使用Suitecrm 7.9.1 每当我尝试创建销售线索时(即提交创建销售线索表格后),我都会遇到以下错误。 每当我尝试导入csv文件时,都会遇到相同的错误。仅在实时服务器上发生此错误 Fatal e
Closed. This question is not reproducible or was caused by typos。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-to
我想在QNX上运行GoogleTestLibrary吗? 但是我收到此错误消息? ldd:FATAL: Could not load library libgtest.so.0 首先,我使用make命
尝试编译代码时,IDE 中显示的 fatal error 和非 fatal error 之间的主要区别是什么? 在这两种情况下,编译器都会显示一条错误消息,并且不会编译程序。 fatal error
当一个人试图编译代码时,在 IDE 中显示的 fatal error 和非 fatal error 之间的主要区别是什么? 在这两种情况下,编译器都会显示一条错误消息,并且程序不会被编译。 fatal
这个程序发出app: 2015/10/24 11:28:15 example.go:22: open some-crazy-non-existent-file: no such file or dir
因此,我正在从事一个项目,但是由于不断收到错误和警告,所以我遇到了一个问题。我对PHP还是很陌生,所以要保持柔和。使用PHP 5.5可以正常运行该程序。但是,当我在PHP 5.6中运行该程序时,会收到
在 WiX 安装程序中 - 如何自定义或覆盖 fatal error 对话框 ()?我想显示详细的错误消息而不是默认设置失败消息。 选项: 是否可以在 WiX 中调整 fatal error 对话框的
我正在尝试通过 Android 工具 > 重命名应用程序包 在 eclipse 中重命名我的 android 应用程序包。它正在生成错误说 A Fatal error occurred while p
我正在使用 Ubuntu 13.10 x64,我正在做一些开发人员正在使用 Windows 的项目,我最近将 git config core.eol 更改为“lf”和 core .autocrlf 为
嗯..世界上的每个服务都可以连接到我的动物园管理员,除了 kafka。下面是我在 server.properties 文件中的连接字符串 zk.connect=1.dzk.syd.druid.neo.
我正在 Java EE 7 中尝试一些东西,我已经构建了一个示例应用程序,可以在此处找到 https://github.com/kenparker/moviplex7.git . 在此过程中,我了解到
我正在尝试使用 bitbucket 中的 ssh 克隆我的存储库,但是每当我克隆存储库时,我都会得到: Connection to bitbucket.org closed by remote hos
该代码包括从一系列数字创建一个数组,以及第三个参数,其中它指示数字的步长,如果它的步长为 2,例如它来自 [1,3, 5] 代码工作正常,除非我以负数作为参数传递 step,例如NumberRange
我正在尝试在我的 ubuntu 中运行一个简单的 git pull 命令。直到几天前,它还可以完美地工作。不是它显示致命:无法访问“https://xxxxxx@bitbucket.org/repon
我知道已经有人问过类似的问题。 但是,我认为我的问题是由于我之前犯的一个错误,因此有所不同:让我解释一下。 一切都如我所愿顺利进行: git add . 我本地存储库中的所有文件。 git commi
我在尝试执行 Jenkins 作业时看到错误。 git 版本 1.8.3.1 Jenkins 2.46.2.1-滚动 我尝试将 git 升级到更高版本,但仍然通过关注 How to install l
Image of the output in the browser 我正在离线处理一个项目。我有一个名为 index.php 的文件。 现在我想在可以编辑的浏览器 sp 中启动。 但是当我尝试通过
我正在AWS的Linux机器上运行RServer Studio。 我尝试安装ModelMetrics的依赖项caret,并收到此错误: auc_.cpp:2:10: fatal error: omp.
我似乎没有重复发帖,所以这是详细信息... 当我使用 XOM(XML 对象模型,Java 库)中的非静态方法 Builder.build() 解析文档时,在 Eclipse 控制台中我得到: [Fat
我是一名优秀的程序员,十分优秀!