We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5290
    • 29 Posts
    A couple of days ago I ran into a problem with the snippet GalleryItemPagination that was posted in the Gallery snippet documentation. A client called me, telling me his website was down. I contacted the hoster and they told me they had taken it offline, because in half a day a 68 GB error.log had been generated. A shocking amount of data! In the log the following lines were endlessly repeated:
    [Thu Apr 19 13:13:57 2012] [warn] [client x.x.x.x] mod_fcgid: stderr: PHP Notice:  Undefined offset: 42 in /var/www/vhosts/MyWebsite.nl/httpdocs/modx_core/cache/site/includes/elements/modsnippet/24.include.cache.php on line 56
    [Thu Apr 19 13:13:57 2012] [warn] [client x.x.x.x] mod_fcgid: stderr: PHP Notice:  Undefined offset: 43 in /var/www/vhosts/MyWebsite.nl/httpdocs/modx_core/cache/site/includes/elements/modsnippet/24.include.cache.php on line 56
    [Thu Apr 19 13:13:57 2012] [warn] [client x.x.x.x] mod_fcgid: stderr: PHP Notice:  Undefined offset: 44 in /var/www/vhosts/MyWebsite.nl/httpdocs/modx_core/cache/site/includes/elements/modsnippet/24.include.cache.php on line 56

    Notice the 'Undefined offset' that apparently takes place in line 56? This is the result of a while loop, that will continue for as long as PHP lets it. In this case, everytime the error was fired it added a little over 2 GB to the error.log. And the biggest snag is that technically it's not really an error. It's a notice, which means that the snippet will run as expected, delivering the desired result, meanwhile creating the dreaded error.log unnoticed.

    So what happens? The snippet iterates through arrays trying to find whatever images come before and after the requested GalleryItem. That works just fine (= no errors or notices), unless the requested GalleryItem does not exist, in which case it never finds a match and continues to iterate until PHP breaks off the process.

    My PHP skills are basic and I didn't have the courage to try and rewrite the snippet itself, afraid that I might break it in other places. Instead I used a combination of Gallery and FilelLister to test for the existence of the requested Gallery item, before passing its ID to the pagination snippet. But for some reason the snippet always managed to circumvent my efforts. Eventually I saw no other option but to completely remove the snippet.

    I think the code of the snippet in the documentation should be rewritten, before others fall into the same trap. But I don't feel qualified enough to do it, so maybe someone else could have a go? GalleryItemPagination was used in combination with Gallery 1.5.0 RC1 and ran on a website using MODX 2.2.1 PL. The server used PHP 5.3.x and Apache 2.x. (I can't test for the exact version numbers right now).
      A computer program is a utilitarian typographer's dream - a functioning machine composed completely of type. (John Maeda)
      • 32316
      • 387 Posts
      have you filed a bug report? - that would be the quickest way for this to be resolved
        • 5290
        • 29 Posts
        No I haven't. It's an extra and not an official part of MODX, so I assumed that the bugtracker would not be the right place for a bug report. That's why I decided to post it here.
          A computer program is a utilitarian typographer's dream - a functioning machine composed completely of type. (John Maeda)
          • 5290
          • 29 Posts
          Found the Gallery Github page and added this problem to the Issue List.
            A computer program is a utilitarian typographer's dream - a functioning machine composed completely of type. (John Maeda)