1

Trying to get this json api to work for us and keep running into issues. Here, when trying to list all items, it throws the following PHP error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 65552 bytes) in /home/accesstrucks/craft/app/framework/YiiBase.php on line 618

There are only 100 listings currently, but this is just for testing. Which is nothing compared to how many listings there will be when live.

Here's my code:

return [
  'endpoints' => [
    'alltrucks.json' => [
      'elementType' => 'Entry',
      'criteria' => ['section' => 'trucks'],
      'paginate' => false,
      'transformer' => function(EntryModel $entry) {
        return [
          $entry->year.' '.$entry->manufacturer.' '.$entry->model,
          (string)$entry->author,
          !empty((string)$entry->category[0]) ? (string)$entry->category[0] : null, 
          !empty($entry->listingPhotos[0]->url) ? str_replace('/images/uploads/listings/', '', $entry->listingPhotos[0]->url) : null,
          ($entry->saleType=='new') ? '0' : '1',
          (string)$entry->featured,
          ($entry->saleType->label=='new') ? '0' : '1',
          $entry->transmission,
          (string)$entry->dateUpdated,
          $entry->mileage,
          $entry->price
0

Your php.ini file's memory_limit setting is set to 32M.

You'll want to bump that up to something higher like 256M.

3
  • Am i running a the risk of overloading the memory on the site though? It seems surprising that such a simple query would be so demanding on memory.
    – Noah Yamen
    Feb 15 '17 at 19:27
  • Probably not? 32M is a pretty low memory limit setting.
    – Brad Bell
    Feb 15 '17 at 19:54
  • Good to know. Updated it and its running fine now, as would be expected.
    – Noah Yamen
    Feb 15 '17 at 19:56

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.