Answers.Body: <p>You may want to try further limiting what you're returning from the API call. </p>
  
  <p>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:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte">https://stackoverflow.com/questions/415801/allowed-memory-size-of-33554432-bytes-exhausted-tried-to-allocate-43148176-byte</a></li>
  <li><a href="https://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml">https://stackoverflow.com/questions/561066/fatal-error-allowed-memory-size-of-134217728-bytes-exhausted-codeigniter-xml</a></li>
  </ul>
  
  <p>That is a PHP ini setting. If you don't have access to the php.ini file, you have to call <a href="http://php.net/manual/en/function.ini-set.php" rel="nofollow noreferrer">ini_set()</a>
   somewhere in your source code. </p>
  
  <p>This statement sets no memory limit, although I do not recommend using this: <code>ini_set('memory_limit','-1');</code></p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-23T10:43:19.983Z
Answers.Text: Thanks a lot @Angelo! Increasing the memory limit to `256M` solved the problem.
Answers.UserDisplayName: user2190590
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-22T20:11:34.347Z
Answers.LastActivityDate: 2017-11-22T20:16:49.893Z
Answers.LastEditDate: 2017-11-22T20:16:49.893Z
Answers.UserDisplayName: Angelo
Body: <p>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.</p>
  
  <pre><code>'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,
  
          ];
      },
  ],
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-21T16:40:00.467Z
Comments.Text: 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.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-22T17:08:37.797Z
Comments.Text: 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)`
Comments.UserDisplayName: user2190590
Tags: <categories><plugin-elementapi><json>
Title: Element API with multiple categories gives back error 500
ThreadText: # Element API with multiple categories gives back error 500
  
  (Asked by: username_0 on 2017-11-21)
  
  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,
  
          ];
      },
  ],
  
  ```
  
  **Tags:** categories, plugin-elementapi, json
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: Thanks for the tip @username_1: I found this error message in the Craft logs: `PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 65552 bytes)`  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-11-22. Score: 1 | Accepted answer
  
  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()](http://php.net/manual/en/function.ini-set.php)
  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.
  
  > **Comments:**
  > **username_0**: Thanks a lot @username_2! Increasing the memory limit to `256M` solved the problem.  
  
  ---
  
  