0

I need to display a large list of channel entires...between 500 and 800 entries. The list is simply a list of names in alphabetical order. When I run this query, I run out of PHP memory. I've tried to disable all parameters that I can, but I still get a memory error. This list can be cached and refresh once a day or so, but I can't even get to that point without running gout of memory.

Is there anything that can be done to output such a large number of channel entries, other than upping the PHP memory limit (which I understand is a bad idea)?

5
  • You might be better off using the {exp:query} module, and lol wut? Upping your PHP memory limit is a function of need; if you need it and your server has ample resources, just do it. – jrothafer Jul 30 '15 at 13:07
  • ok. In my search, in every suggestion on how to deal with PHP memory limit errors, someone inevitably says "don't up your PHP memory, fix your script" – Bardo_J Jul 30 '15 at 13:44
  • What "disable" parameters are you using in your query? Is the name the title of the entry or in a custom field? Do you have a lot of custom fields in this field group? Are there some you don't need? If you use the 'limit' parameter how high can you set the limit before you get the memory error? – AllInOne Jul 30 '15 at 14:34
  • <ul> {exp:channel:entries channel="the_long_list_in_question" status="open|another status|yet another status" orderby="custom_field_name" limit="1500" sort="asc" cache="yes" refresh="720" dynamic="no" disable="categories|category_fields|member_data|pagination"} <li>{custom_field_name} {if another_custom_field}- {another_custom_field}{/if}</li> {/exp:channel:entries} </ul> – Bardo_J Jul 30 '15 at 14:41
  • 1500 was just in there for testing. it works fine up to a limit of around 550-600 – Bardo_J Jul 30 '15 at 14:42
1

I would do as @Ballonatic says, and use pagination. But if this isn't an option, you can set your PHP Mem limit higher.

You can change your php.ini file to reflect this:

memory_limit = 64M

Replease 64M (or whatever your's is set as) with and upped value. Another option, if you (for some unfathomable reason) only want the memory raised for that particular page, but remain at it's lower setting for all other pages, you can turn PHP on for that template and use this PHP function:

ini_set('memory_limit', '64M');

That will change the memory limit for the duration of the script execution, but will return to it's php.ini set value on next script execution (some other page).

8
  • it sounds like if my script is solid/doesn't have a memory leak somewhere, upping the PHP memory_limit isn't as bad a thing to do as I'd been lead to believe? and no, pagination isn't an option. and my javascript chops aren't up to snuff enough to do that pagination/ajax trickery he mentioned – Bardo_J Jul 30 '15 at 13:57
  • SSH in to your server. Run this command: top What are the memory results under standard load? If your server set up is intelligent, you never reach close to your limit, unless you're on a shared hosting environment, in which case, who cares if you push the machine? Go for it, mang. If you're using EE channel class or channel:entries tag, you're covered for leaks. – jrothafer Jul 30 '15 at 14:22
  • Top results: Mem: 5414908k total, 4653316k used, 761592k free, 268096k buffers - I'm on a VPS – Bardo_J Jul 30 '15 at 14:28
  • Aww yeah. That's fine, just up the limit for that page (use the ini_set method). The worst thing you can do is not resolve your problem. If you're already hitting the memory limit, then upping it and still hitting it won't break your shit :) – jrothafer Jul 30 '15 at 14:34
  • so i can just add that line to the top of a template? (trying that and it's not working....even tried throwing a 128M number in there. also tried wrapping it in php tags. any thoughts? – Bardo_J Jul 30 '15 at 14:55
0

You could use pagination. Or if you want the whole list loaded on one page you could use pagination in combination with ajax. Than you load one batch at a time and add it on your page.

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.