How to limit complexity of rules


i am using the Hoa Ruler in my project to handle configurable business logic. Sometimes i have the problem that the rule is so complex that the compiler runs into an fatal error (PHP Fatal error: Allowed memory size).

Is it possible to define the maximum degree of complexity? For example depending on the number of operators or something else.

i was unable to find a feature for my problem in the documentation …

Well I never face that type of situation. But perhaps you have small piece of rules and say use this one and this one that exist previously. So the compiler have something smaller to compile and after that the cache will handle the rest.

But, it could be very interesting for us to have example (if possible) of complex rules, to try to optimise the library.

It’s a good start

Hello @mbb84,

Sorry for the late reply.

  • I need to understand what part of the code throws the fatal error related to the memory allocations.
  • I also need to see an example of your rules if possible. I wonder what size a rule must have to allocate a big amount of memory.
  • Finally, what the maximum memory your PHP server can allocate?


Thx for your fast answers … i will try to give you more details …

I am using the Hoa Ruler to let our users define complex business logic. In this case the user has defined a rule that checks if a business object contains a specific string. The problem was that the user was using the OR operator. After rewriting the rule with the IN operator it works.

The list that should be checked was very long … (900 entries).


(data(“collective_agreement”, false, “”) = “string 1”) OR (data(“collective_agreement”, false, “”) = “string 1”) OR (data(“collective_agreement”, false, “”) = “string 1”)

As you can see there is a special “data()” operator written by ourselves. It is possible that this operator is part of the problem.

Memory Limit: 512mb


PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 20480 bytes) in vendor/hoa/compiler/Llk/Parser.php on line 59

For me it is absolutely clear that the memory error is not a bug or an error in the Hoa lib. The problem is the complex logic and the “stange” try of the user :-). But i have to handle this situation and it is important to avoid this fatal errors in production environments.

This is the reason i was searching for a smart way to avoid to complex rules (a simple string length check is not good enough).

Currently we are using a very simple workaround … each rule hast to be executed with the Hoa lib before the rule will be activated in the production environment (not perfekt but it works for the moment) …

For what I understand, the data function is fetching the data for each call. Maybe some cache would be useful to solve the problem, thoughts?

Yes this is one of many possible solutions. What I hear from your answers is that there is not a possibility to set a limit for the complexity of rules. She problem should solve in another way … works for me …

thx for your answers …

The rule is not complex here. The issue is that data fetches too much data each time, so it overflows your memory :-).