We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 45516
    • 14 Posts
    I know it's been posted numerous times already, I've done as much troubleshooting as I can, I'm now turning to the community for help. I've already posted this same content to Bug #9667, since it seemed relevant.

    Needless to say, the "Error caching lexicon topic" error is driving me crazy for our MODX instance.

    We initially installed the product to an intranet site, and had no issues.

    Since migrating to our public Web domain, the issue has been continuous and pervasive. I've checked the core.config files to make sure the Web host info is correct, and it is.

    We're running three contexts, routing traffic using bertoost's GatewayManager plugin. I've set up the secondary contexts' site_start, site_url, http_host, etc.


    I'm consistently seeing errors like the following:

    [2013-10-11 14:55:07] (ERROR @ /connectors/resource/index.php) Error caching lexicon topic lexicon/en/core/default

    [2013-10-11 14:55:11] (ERROR @ /connectors/system/settings.php) Error caching lexicon topic lexicon/en/core/setting

    [2013-10-23 09:28:07] (ERROR @ /connectors/lang.js.php) Error caching lexicon topic lexicon/en/core/resource

    [2013-10-23 15:05:16] (ERROR @ /connectors/element/propertyset.php) Error caching action map mgr/actions

    [2013-10-24 14:49:41] (ERROR @ /connectors/resource/locks.php) Error caching lexicon topic lexicon/en/core/default

    [2013-10-24 15:41:36] (ERROR @ /connectors/layout/modx.config.js.php) Error caching lexicon topic lexicon/en/core/resource

    Sometimes the log will throw one of the above errors and the manager will continue to respond normally; sometimes it will start throwing the "Unexpected Token" error (see attached screenshot). When I check the "network" tab in Chrome developer tools, basically what happens is that after the cache error happens, our system will start throwing 404 and / or 502 errors. It seems like at some point, the cache corruption causes requests to use too much memory and then the request thread fails before it can return a result.

    In most cases this appears to only affect the manager, but yesterday I saw the 502 error on the front-end for one of our contexts. The initial index.php controller would return a 502 error for pages on the site. Sometimes you could refresh the page and the request would complete, but then move to another page and the error would happen again.

    Our system:

    Revolution 2.2.8-pl Traditional
    Gentoo 2.6.34-r6
    MySQL 5.1.56
    PHP Version 5.3.27-pl0-gentoo
    PHP memory limit is set to 128
    Max Execution Time 120


    • Compress JS and Compress CSS are both disabled in the MODX system settings.
      The core/cache/ folder is set to 755 permissions, where Apache is the owner and group.
      We are running memcache(d) on these Web servers.

    We are running a load-balanced configuration for the Web servers, but the MODX instance is only connected to one database.

    I am not the primary server administrator for the systems hosting our MODX instance, but I have a direct line of communication with him. If I need to get some apache error logs, etc. from him I likely can, he would need to block out the time to retrieve them.

    I just want to state that our organization loves the potential of MODX, but cannot wholeheartedly endorse it for our major public Web site because of this issue. Currently we're using it for several subdomains / microsites, but would love to move our major public Web presence on to it, but at this point it's a complete non-starter due to this issue.

    For now I've completely disabled lexicon caching to see if it stops this problem. We don't have any intention of using internationalization features in the near future, so if disabling the lexicon cache makes things more stable we're willing to take the performance hit in the manager, but this is a real problem for us. I would love, LOVE to give MODX a whole-hearted "thumbs up" to my management team, but simply can't right now.
      • 3749
      • 24,544 Posts
      The first thing to try is turning off E_NOTICE error reporting (if it's on). That won't solve the problem, but it may hide it. E_NOTICE reporting should be off in production sites anyway.

      The unexpected token message often means that a plugin or CMP is throwing an E_NOTICE error and the error message is crapping up the return value of a processor.

      One possible cause for both errors might be a typo in a lexicon file. Lexicon files need to be valid PHP and all strings in them need to be defined.

      This article might help give you some clues on how to find the problem: http://bobsguides.com/blog.html/2013/05/22/debugging-cmps-a-horror-story/

      It's also possible that you just have a corrupted file in your MODX install. That's fairly common if you transfer the MODX files individually with FTP. [ed. note: BobRay last edited this post 10 years, 5 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 45516
        • 14 Posts
        Hi, thanks for the reply Bob.

        I actually came across your blog entry about a week ago, and have tried to hunt through some of the non-core lexicon entries to see if one of the add-ons we have installed might be the cause of the error. I haven't found anything yet, but I'll have more time this week to keep looking.

        I'll have to check with the system administrator to see if he can turn off E_NOTICE errors. As far as the installation goes, I'm fairly certain he uploaded the .zip file and unpackaged it on the original server, but I don't know how he moved it to the production site (i.e., did he FTP it, or did he re-package and unzip at the new file location).

        Obviously I could have him upgrade to 2.2.10, which might solve the problem if there's a corrupt file, but I think he'd prefer to just hold out for 2.3 so he only has to do one upgrade.

        For now I may just create a simple cache-clearing plugin that fires on a relatively uncommon manager system event (OnDocFormPrerender, maybe?) that clears the lexicon topics.

        I guess my question is at this point, has there ever been a common link or thread identified behind the nature of this issue? I know about the problem addressed in 2.2.5 surrounding the GoDaddy / Rackspace problem with flock(), but clearly that wasn't the only source of the problem if it's still happening. Besides the problems I'm having, I've seen several mentions of it happening on 2.2.6 and up for other users.

        Since we are running memcache(d) on these servers, would it make sense to use an alternative cache handler than xPDOFileCache? There's not much detailed documentation on this. I know opengeek posted a blog entry outlining some basic steps to set this up, but some of it was beyond my current technical know-how (I'm familiar with the basics of PHP, and am usually pretty good at intuiting stuff, but am far from being a "real coder").
          • 3749
          • 24,544 Posts
          I don't know much about using memcached and I agree that cache corruption has been a perennial problem for a relatively small minority of MODX users. I don't think anyone knows why.

          There is a kind of brute-force snippet for clearing the MODX cache here: http://modx.com/extras/package/cacheclear

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
          • I've always gotten occasional cache errors, even on the MODx Cloud. Either it can't save to the cache, or it can't load from the cache. For example, on my localhost right now I have
            [2013-10-25 19:55:44] (ERROR @ /revo2210/connectors/system/settings.php) Error caching lexicon topic lexicon/en/core/namespace
            [2013-10-27 13:01:33] (ERROR @ /revo2210/connectors/system/settings.php) Error caching lexicon topic lexicon/en/core/namespace

            And on my sottwell.com production Cloud site I have a whole bunch like this
            [2013-10-28 10:21:54] (ERROR @ /index.php) Could not retrieve data to cache for resource 50

            I didn't check them all, but resource #50 happens to be a Static Resource linking to a video download.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 45516
              • 14 Posts
              Hmmm, that's interesting Susan, thanks for the reply. In seems based on what you're telling me that a cache file error isn't necessarily indicative of a problem, which my experience bears out. Sometimes I'll see a dozen errors like your example, or the ones in my original post, over a six-hour period without any issues, and then out of the blue, BAM, the "Unexpected Token" error starts appearing. As soon as I delete the /core/cache/ folder, it goes away.

              It's the randomness of it that's so frustrating. Had it happen just this morning, someone behind me was updating a resource then turns around and says, "Uh, I think MODX broke again."

              Delete the cache, and all is well.

              However, I've discovered something else that's going on that may or may not be related -- I've discovered that I cannot create a resource at the context root. If I right-click on a context name, then select "Create > Create a Document Here," the system immediately goes to an internal server 500 error.

              This is making me wonder if I've got some kind of file / folder permission problem going on. I know there's a system setting to allow / disallow creating resources at the context root, and I've verified that I have it enabled.

              I can create a resource as a child to another resource, save it, and then change the parent to the context root, but I can't just create a resource directly at the root.
                • 3749
                • 24,544 Posts
                Do you have any plugins running that are connected to OnDocFormSave or OnBeforeDocFormSave? That would be the first place to look for a culprit (particularly OnBeforeDocFormSave).

                Do you see anything in the error log when it happens?


                Using Chrome Dev. tools and looking at the network tab stuff when it happens might give you a clue (http://bobsguides.com/blog.html/2013/05/22/debugging-cmps-a-horror-story/).
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                • There's also a system setting to allow/disallow creating new resources in the Tree root level. This is to prevent users from breaking site menus, where the layout requires a limited number of top-level resources. Although why hitting this restriction in system settings should cause a server error is another question.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 45516
                    • 14 Posts
                    Well I've been unable to sort out the the problem with not being able to directly create a document to the context root. This is somewhat concerning, but has any number of easy workarounds, so I'm not going to worry about it for now. After we upgrade to 2.3, whenever it's released, we'll revisit this.

                    As far as the cache error problem --- I've absolutely determined that it's the corrupt cache files that's causing the errors. I started by turning off the action map cache and lexicon JS string cache, and the problem still occurred. Then I disabled the lexicon topic caching options (both for core and non-core lexicons), and have not had a single problem since with the manager or site front-end erroring / throwing a 502.

                    In my testing, the corrupt cache most directly affects one of these two PHP scripts:

                    /connectors/lang.js.php

                    /connectors/layout/modx.config.js.php

                    The GET string for lang.js.php usually looks something like:

                    http://site.mydomain.com/connectors/lang.js.php?ctx=mgr&topic=topmenu,file,resource,welcome,configcheck,ace:default&action=1


                    What appears to be happening is lang.js.php will attempt to retrieve one of the listed topics from the cache file, run into a problem retrieving the data, then throw a 500 error.

                    At this point I'm not exactly sure what's happening, but it looks like the initial error then cascades down.

                    At that point, there's portions of the page that don't have information they need from the cache. For instance, modx.config.js.php no longer has all of the options it needs from the lexicon cache, and throws the "unexpected token" error.

                    The other thing that may be exacerbating the problem is that it looks like the load balancers tied to our domain start assuming that anything in the site.mydomain.com/connectors/ folder is a "bad gateway," because attempts to refresh the page after that lead to one of those two scripts returning as a 502 error. Attempts to move away from the page where the error first happened will sometimes load successfully, if one of the other servers on our load balancer handles the request, since the cache file remains uncorrupted on that server instance. But most of the time the manager is just dead until the cache is cleared. Sometimes you can refresh the page and have portions of the screen render, but because there are still values missing from the unloaded, corrupted cache, a string for "undefined" will get inserted in several places in the javascript, causing additional errors.

                    I realize that as an open source project, and that much of the MODX product is truly a labor of love. I would absolutely love to evangelize MODX to everyone I know, because the core concept and potential of MODX is obvious. I recognize fixing problems like this are difficult since replicating the problem is often specific to the installation environment. It's just frustrating to have this specter of instability constantly floating overhead with our MODX install.

                    Ideally this issue would be fixed permanently in a future release, though I don't know how much attention has been paid to this since the 2.2.5 flock() fix rolled out. One thing I thought of while troubleshooting and looking for workarounds was I found myself wishing that there was a MODX system event for writing an error to the log, something like, OnWriteLogError. Because what I'd do is simply write a plugin to clear the cache anytime a lexicon-related error appeared in the log.

                    [ed. note: felonius last edited this post 10 years, 4 months ago.]
                      • 3749
                      • 24,544 Posts
                      I had a similar problem (as described in the blog post). Mine was caused by a single lexicon file containing a PHP syntax error. I had installed and removed the Gallery plugin, but its lexicon file remained for some reason and contained an error.

                      One thing you might try, though it's tedious, is to load those lexicon topic files in a good code editor like PhpStorm, which will immediately flag any syntax errors.

                      Another way would be to write a little utility snippet that "includes" each lexicon file. It you hit a bad one, you'll get a syntax error message that should tell you the line number.

                      The "unexpected token" error is often caused by any PHP error thrown in a processor or plugin.
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting