【问题标题】:Allowed memory size of 134217728 bytes exhausted (tried to allocate 84 bytes)134217728字节的允许内存大小用尽(尝试分配84字节)
【发布时间】:2017-05-18 13:00:33
【问题描述】:

我收到了这个错误

允许的内存大小为 134217728 字节已用尽(尝试分配 84 字节) /url/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php 271

我已经测试了一段时间,但是每当$data1$data2 之间的范围太大时,就会出现错误,但我仍然认为查询对于服务器来说应该不那么难,所以我想我是实际上查询生成器做错了什么。现在我正在通过仅过滤日期和单个交易来重现错误。

function getTicketsList($tpv, $salesman, $customer, $data1, $data2){

if(count($tpv)==1){
    $tpv = array($tpv);
}

$qb = $this->createQueryBuilder('t');

$qb
    ->select('t.id_tickets', 't.ticket_code', 's.name AS seller', 'c.name AS customer', 'c.surnames AS customer_s',
            't.created_client_date', 't.comment', '(t.total_amount - t.total_net_amount) AS tax_amount', 't.total_amount', 't.discount','c.email AS customer_email')
    ->join('Entity\Seller', 's', 'WITH', 's = t.seller')
    ->leftJoin('Entity\Customer', 'c', 'WITH', 'c = t.customer')
    ->distinct();


$filter = $qb->expr()->andx();

if($salesman){
    $filter->add(
            $qb->expr()->eq('t.seller','?1'));
    $qb->setParameter(1, $salesman);
}
else{
    $filter->add(
            $qb->expr()->in('t.tpv', ':tpv_id'));
    $qb->setParameter('tpv_id', $tpv);
}

if($customer){
    $filter->add(
            $qb->expr()->eq('t.customer','?2'));
    $qb->setParameter(2, $customer);
}

if($data1){
    $filter->add(
            $qb->expr()->gte('t.created_client_date', ':small_date'));
    $qb->setParameter('small_date', $data1);
}

if($data2){
    $filter->add(
            $qb->expr()->lte('t.created_client_date', ':big_date'));
    $qb->setParameter('big_date', $data2);
}

$qb->where($filter);


$result = $qb->getQuery()->getResult();

return $result;

}

是否有人注意到我的查询构建器功能中存在一些错误、不良做法或有一些改进性能的建议?

【问题讨论】:

  • 你试过这个ini_set('memory_limit', '2048M');
  • 使用分页,只是你一次获取太多记录并且内存不足
  • @Nebojsa 是的,但没有工作,很可能是托管服务(idk)有一些限制。
  • @malarzm 在 Mysql Workbench 中执行相同的查询会返回 3170 行的快速结果,这让我认为问题出在教义或我执行查询的方式上。

标签: php doctrine-orm


【解决方案1】:

在第 271 行之前添加以下代码:

ini_set('memory_limit', '2048M');

它会临时将你的 php memory_limit 设置为 2048M。

【讨论】:

    猜你喜欢
    • 2016-04-18
    • 2013-08-09
    • 2021-12-29
    • 2017-07-23
    • 2018-02-23
    • 2014-11-20
    • 2017-10-30
    • 2017-08-11
    • 1970-01-01
    相关资源
    最近更新 更多