1

This works fine on localhost but crashes on remote Server. I can return one category, but it will crash when I try to display multiple categories. I also tried to save the categories in a variable and return the variable, which again worked on localhost but not on remote Server.

'programevent.json' => [
    'elementType' => ElementType::Entry,
    // 'cache' => true,
    'elementsPerPage' => 999,
    'paginate' => false,
    'limit' => 999,
    'criteria' => ['section' => 'program','type' =>'Event'],
    'transformer' => function(EntryModel $entry) {
        HeaderHelper::setHeader([
            'Access-Control-Allow-Origin' => '*'
        ]);
        $parent = $entry->getParent();

        return [
            'title' => $entry->title,
            'url' => $entry->url,
            'id' => $entry->id,
            'description' => (string) $entry->description,
            'level' => $entry->level,
            'themes' => array_map( function (CategoryModel $category) {
                return [
                    'id' => $category->id,
                    'title' => $category->title
                ];
            }, $entry->themes->find()),
            'kindOfEvent' => array_map( function (CategoryModel $category) {
                return [
                    'id' => $category->id,
                    'title' => $category->title
                ];
            }, $entry->kindOfEvent->find()),
            'languages' => array_map( function (CategoryModel $category) {
                return [
                    'id' => $category->id,
                    'title' => $category->title
                ];
            }, $entry->languages->find()),
            'parent' => $parent ? [
                'title' => $parent->title,
                'number' => $parent->number,
                'url' => $parent->url,
                'shuttleLine' => array_map( function (CategoryModel $category) {
                    return [
                        'title' => $category->title,
                        'color' => $category->color
                    ];
                }, $parent->shuttleLine->find()),
            ] : null,

        ];
    },
],
  • What's the 500 ISE error message? If it's Craft generated, it'll be in craft/storage/runtime/logs. If it's web server generated, it'll be in your web server's error logs. – Brad Bell Nov 21 '17 at 16:40
  • Thanks for the tip @BradBell: I found this error message in the Craft logs: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 65552 bytes) – user2190590 Nov 22 '17 at 17:08
1

You may want to try further limiting what you're returning from the API call.

The server may just have a low PHP memory size limit set. There are many answers to fix the PHP memory size bytes exhaustion error. Here's a few:

That is a PHP ini setting. If you don't have access to the php.ini file, you have to call ini_set() somewhere in your source code.

This statement sets no memory limit, although I do not recommend using this: ini_set('memory_limit','-1');

Try the lowest amount that you can afford before deploying application, as this can cause server issues if too much memory is allocated to by a bad PHP script.

  • Thanks a lot @Angelo! Increasing the memory limit to 256M solved the problem. – user2190590 Nov 23 '17 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.