Element API with multiple categories gives back error 500 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' =&gt; [
    'elementType' =&gt; ElementType::Entry,
    // 'cache' =&gt; true,
    'elementsPerPage' =&gt; 999,
    'paginate' =&gt; false,
    'limit' =&gt; 999,
    'criteria' =&gt; ['section' =&gt; 'program','type' =&gt;'Event'],
    'transformer' =&gt; function(EntryModel $entry) {
        HeaderHelper::setHeader([
            'Access-Control-Allow-Origin' =&gt; '*'
        ]);
        $parent = $entry-&gt;getParent();

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

        ];
    },
],
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:


https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte
https://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml


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.