【发布时间】:2019-07-17 05:13:12
【问题描述】:
我在 OctoberCMS 中制作了一个组件,它导致了内存错误。 该组件只有一个非常简单的功能。 我不知道为什么会导致这样的错误。
我在 php.ini 中将 memory_limit 编辑到了 1024M,但没有任何改变。
组件文件
<?php
namespace Jiwon\Byapps\Components;
use Cms\Classes\Page;
use Cms\Classes\ComponentBase;
use Exception;
use Jiwon\Byapps\Models\Comment;
class Comments extends ComponentBase
{
public $comments;
public function componentDetails()
{
return [
'name' => 'Comment List',
'description' => 'comment list'
];
}
public function defineProperties()
{
return [
'display' => [
'title' => 'number of the comments',
'description' => 'number of the comments list',
'default' => 10,
'validationPattern' => '^[0-9]+$',
'validationMessage' => 'only number'
],
];
}
public function onRun()
{
$this->comments = $this->loadComments();
}
protected function loadComments() {
$query = Comment::all();
if ($this->property('display') > 0) {
$query = $query->take($this->property('display'));
}
return $query;
}
}
?>
我把这个组件放在partials的旁边,这个错误显示在每个页面中。
允许内存大小134217728字节用尽(尝试分配8192字节) /home/ljw/public_html/byapps_cms/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php 第290行
评论模型文件
<?php namespace Jiwon\Byapps\Models;
use Model;
class Comment extends Model
{
use \October\Rain\Database\Traits\Validation;
public $timestamps = false;
public $connection = 'byapps';
public $table = 'BYAPPS_comment_data';
}
【问题讨论】:
-
Allowed memory size of 134217728 bytes exhausted通常意味着你在某个地方出现了无限循环。查看您的代码或发布更多数据,例如您的模型评论,看看是什么原因造成的。 -
@SergheiLeonenco 我添加了评论模型。这只是一个简单的模型。我什至想不出任何会导致无限循环的事情。
-
试试
memory_limit = 1inphp.ini,别忘了重启服务器。 -
@Jiwon 你在本地系统工作吗?
-
@BhavinThummar 是的,我每次编辑 php.ini 文件时都会重新启动服务器。
标签: php mysql laravel octobercms