We are using Token for a large .EDU site which has 29 content types, 167 fields, 18 vocabularies, and 34 contrib modules. When Token and Business Rules are both enabled we receive the following Fatal error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 140523879 bytes) in /srv/bindings/611d45201f254779b7491001c71e7441/code/core/lib/Drupal/Core/Database/Statement.php on line 59

When Token is disabled, there is no memory error.

We tried to recreate the error on a clean D8 install, but was unable to replicate it. That's when we realized that it was similar to issues we had on large Drupal 7 sites. With Drupal 7, we were able to resolve this issue by using an awesome module called Token Tweaks. Token Tweaks helped when accessing the token tree ui by limiting the depth of displayed tokens which stopped memory errors.

Since the site is so large and heavily uses Token, we don't have a way to give you step by step on how to replicate it. However, I would be happy to add Dave or maintainers to our Pantheon dashboard to clone the site.

We appreciate all of the hard work that goes into this module and we are dead in the water without it. :D


C13L0 created an issue. See original summary.

C13L0’s picture

Issue summary: View changes
Berdir’s picture

Strange, that's as part of a query, doesn't seem like something token specific.

It would help a lot if you could enable verbose error display, so you can see the full backtrace of that error. You could also try our past logging project to get a better error with backtrace: http://drupal.org/project/past

Token has known memory issues, already was a big issue in 7.x as you said. But that's mostly about the token UI, the only real solution there is to build a UI that uses ajax lazy loading to expand the tree and not build/load everything upfront.

PS: You probably heard of it, but https://www.drupal.org/project/paragraphs can often result in fewer content types and more flexibility, as structures can be put together in more flexible ways. But that depends a lot on what you have need on a site. Another option is defining custom entity types, especially when a lot of what node does by default is not needed (like showing on a page with alias/menu/... integration or if revisions and/or translations aren't needed).

C13L0’s picture


Thank you for the insanely fast reply! I installed past module and enabled Past, Past Database Backend, and Past Simpletest Backend and received the following error message:

[type] (string): 1
[message] (string): Allowed memory size of 268435456 bytes exhausted (tried to allocate 138927937 bytes)
[file] (string): /srv/bindings/611d45201f254779b7491001c71e7441/code/core/lib/Drupal/Core/Database/Statement.php
[line] (string): 59
Allowed memory size of 268435456 bytes exhausted (tried to allocate 138927937 bytes)
Machine name
Sat, 05/27/2017 - 19:40

Our dev site is on Pantheon
PHP Version
Memory limit

Thank you for the suggestion of Paragraphs, I'm familiar with it. We are building a "master" distro/template and will be using it to spin up an initial 21 sites using Pantheon's upstream. Since I'm the front end dev, I'm not able to comment on why we are doing things one way vs another. However, I don't think our use case with Token is out of the ordinary.

I'm still searching for a solution and have also notified the maintainer of Business Rules of this issue. Business Rules is a very promising module and I predict it will soon be the go-to replacement for Rules in D8.

Please let me know of any additional information that I can provide.

Berdir’s picture

Hm, that's not really useful yet. Since it's a fatal error, can you see more information in /admin/reports/dblog? past afaik currently has a bug with that on PHP7.

Can you provide more information on when it happens? Does it only happen when you actually want to look at a token UI or also on other pages?

jeppy64’s picture

Hi Guys,

Here's a little more info. Maybe this could offer some additional thought points for troubleshooting:

Based on the Business Rules interaction instructions, they suggest a parent child type workflow as in: create a condition, create an action, then create a rule and tag your existing condition and action.

Just to try to offer some further info... the error will fire when following these steps:

1: Go to /admin/config/workflow/business_rules/collection
2: Go to /admin/config/workflow/business_rules/action/add
3: Select an action from the dropdown (i tried Show a Message)
4: Click the Continue button - this is where the memory error will show:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 152146117 bytes) in /srv/bindings/611d45201f254779b7491001c71e7441/code/core/lib/Drupal/Core/Database/Statement.php on line 59

*Note: The same error will fire if you try to add a condition first.

I checked the watchdog and nothing is posted to it regarding this error. I was expecting something to show there. That's what brought me to the guess that the admin UI might be having a memory issue due to the field count (my guess leaning towards tokens and ajax). But I am totally guessing there as this is not my forte. I'm just going by D7 situations that I recall.

Is there anything else I can do to help troubleshoot? Please feel free.

DigitalFrontiersMedia’s picture

@cielo & @jeppy64,
Came across this thread while contemplating use of Business Rules for a client project. I concur with jeppy64 that without a stacktrace the likely cause is the large amount of tokens being passed by the AJAX and exacerbated I'm guessing due to something related to the explanation listed under "Why is the AJAX request so large?" on #956186: Allow AJAX to use GET requests. If this is the case, you might be able to do a quick Token Tweak test of your own by changing TOKEN_MAX_DEPTH on line 11 of token.module (http://cgit.drupalcode.org/token/tree/token.module?id=fb05b225ee0c93835f...) from:
define('TOKEN_MAX_DEPTH', 9);
define('TOKEN_MAX_DEPTH', 2);
define('TOKEN_MAX_DEPTH', 3);

If it works, then you can create a patch to manage it until Token Tweaks is ported to Drupal 8 for users with conditions such as yours.

DigitalFrontiersMedia’s picture

P.S. You may want to either lockdown your pantheon dev site with HTTP Basic Authentication or editing the Referrer and Location links from Comment #4 above to keep Google from picking up on it and making it available in public search results.

C13L0’s picture

@DigitalFrontiersMedia. Thank you for pointing out the url in my post! It's been corrected. I also appreciate the advice in #7 and will look into that =)

mausolos’s picture

I am having this issue too. @C13L0, have you all tried anything new? Did you try the TOKEN_MAX_DEPTH tweak at all?