在Doctrine和ini_set中耗尽的允许内存大小不起作用

在Doctrine和ini_set中耗尽的允许内存大小不起作用

问题描述:

I am importing a lot of files in a query, problem is I got a PHP error telling me I exhausted all the memories.

But this problem is occurring only on the production server, not in my local.

I already tried to do a

ini_set('memory_limit', '-1');

and a

set_time_limit ( 0 );

And my code is

public function mediachooserAction(Request $request, $origin = null, $type = null, $term = null)
{
    ini_set('memory_limit', '-1');
    if ($this->container->has('profiler')) {
        $this->container->get('profiler')->disable();
    }

    $entities = $this->getRepository('AppBundle:Media')->findMedias($origin, $type, $term);

    $pagerfanta = new Pagerfanta(new ArrayAdapter($entities));
    $pagerfanta->setMaxPerPage(20);
    if ($request->query->has('page')) {
        $pagerfanta->setCurrentPage($request->query->get('page'));
    }

    return $this->render('backend/ckeditor/mediachooser/index.html.twig', [
        'entities'      => $pagerfanta,
        'origin'        => $origin,
        'type'          => $type,
        'originChoices' => Media::getOriginChoices(),
        'typeChoices'   => Media::getTypeChoices(),
    ]);
}

But this isn't helping.

Do you know how I can fix this issue without doing any optimisation in my program ?

I did a php_value memory_limit 512M in the .httpaccess and it works fine now.

Could be safe_mode (aka poop_mode) as defined in php.ini. Use ini_get("memory_limit") after ini_set('memory_limit', '-1') to see what the new value is.

If you have access to php.ini, you can set the memory limit there too