We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17016
    • 138 Posts
    Does anybody know what could be the reasons for these error-messages in our error-log in MODx 2.0.5 and what we can do to solve these problems?

    Unfortunately our server was forced down because of out of RAM-memory after sending out a newsletter with links to our website. While this period we got more than 100.000 error-messages in about 2 hours.

    Some of these are for example:

    (ERROR @ [...]/www/modx/core/model/modx/modx.class.php : 1633) Recoverable error: Argument 2 passed to modX::getChunk() must be an array, string given, called in [...]/www/modx/core/cache/elements/modsnippet/45.include.cache.php on line 9 and defined

    (ERROR @ [...]/www/modx/core/cache/elements/modsnippet/85.include.cache.php : 9) PHP warning: mysql_query() [<a href=’function.mysql-query’>function.mysql-query</a>]: Access denied for user ’nobody’@’localhost’ (using password: NO)

    (ERROR @ [...]/www/modx/core/cache/elements/modsnippet/85.include.cache.php : 9) PHP warning: mysql_query() [<a href=’function.mysql-query’>function.mysql-query</a>]: A link to the server could not be established

    (ERROR @ [...]/www/modx/core/cache/elements/modsnippet/85.include.cache.php : 10) PHP warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    (ERROR @ [...]/www/modx/core/cache/elements/modsnippet/85.include.cache.php : 11) PHP warning: mysql_close(): no MySQL-Link resource supplied

    (ERROR @ [...]/www/modx/core/xpdo/cache/xpdocachemanager.class.php : 413) PHP warning: unlink([...]/www/modx/core/cache/objects/modTemplateVar/a422c0812c1a7a2f80d1eb33a110312b.cache.php) [<a href=’function.unlink’>function.unlink</a>]: No such file or directory

    (ERROR @ [...]/www/modx/core/xpdo/cache/xpdocachemanager.class.php : 421) PHP warning: closedir(): 296 is not a valid Directory resource


      • 17016
      • 138 Posts
      Now we made a couple advances and could solve many errors. The remaining and unresolved error-messages at the moment are of these type:

      +++++

      (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 413) PHP warning: unlink(/server/modx/core/cache/objects/modTemplateVarResource/2c3468c42bcf1c299e5839accdace0ea.cache.php) [<a href=’function.unlink’>function.unlink</a>]: No such file or directory

      (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 421) PHP warning: closedir(): 413 is not a valid Directory resource

      +++++

      As far as we have seen these errors are produced within the function deleteTree() (Lines 413 and 421, see code below.) Obviously the requested files don`t exist.

      Does anybody know what are these files about? Did they never exist or have they already deleted before?


      code of the function deleteTree() (in xpdocachemanager.class.php): (Lines 413 and 421 marked with little stars)
          /**
           * Recursively deletes a directory tree of files.
           *
           * @access public
           * @param string $dirname An absolute path to the source directory to delete.
           * @param array $options An array of options for this function.
           * @return boolean Returns true if the deletion was successful.
           */
          public function deleteTree($dirname, $options= array('deleteTop' => false, 'skipDirs' => false, 'extensions' => array('.cache.php'))) {
              $result= false;
              if (is_dir($dirname)) { /* Operate on dirs only */
                  if (substr($dirname, -1) != '/') {
                      $dirname .= '/';
                  }
                  $result= array ();
                  if (!is_array($options)) {
                      $numArgs = func_num_args();
                      $options = array(
                          'deleteTop' => is_scalar($options) ? (boolean) $options : false
                          ,'skipDirs' => $numArgs > 2 ? func_get_arg(2) : false
                          ,'extensions' => $numArgs > 3 ? func_get_arg(3) : array('.cache.php')
                      );
                  }
                  $hasMore= true;
                  if ($handle= opendir($dirname)) {
                      $limit= 4;
                      $extensions= $this->getOption('extensions', $options, array('.cache.php'));
                      $excludeItems = $this->getOption('delete_exclude_items', $options, array('.', '..','.svn','.svn/','.svn\\'));
                      $excludePatterns = $this->getOption('delete_exclude_patterns', $options);
                      while ($hasMore && $limit--) {
                          if (!$handle) {
                              $handle= opendir($dirname);
                          }
                          $hasMore= false;
                          while (false !== ($file= @ readdir($handle))) {
                              if (is_array($excludeItems) && !empty($excludeItems) && in_array($file, $excludeItems)) continue;
                              if (is_array($excludePatterns) && !empty($excludePatterns) && $this->matches($file, $excludePatterns)) continue;
                              if ($file != '.' && $file != '..') { /* Ignore . and .. */
                                  $path= $dirname . $file;
                                  if (is_dir($path)) {
                                      $suboptions = $this->getOption('deleteTop', $options, false) ? $options : array_merge($options, array('deleteTop' => false));
                                      if ($subresult= $this->deleteTree($path, $suboptions)) {
                                          $result= array_merge($result, $subresult);
                                      }
                                  }
                                  elseif (is_file($path)) {
                                      if (is_array($extensions) && !empty($extensions) && !$this->endsWith($file, $extensions)) continue;
      **************************************
      LINE 413:                               if (unlink($path)) {
      **************************************
                                          array_push($result, $path);
                                      } else {
                                          $hasMore= true;
                                      }
                                  }
                              }
                          }
      **************************************
      LINE 421:           closedir($handle);
      **************************************
                      }
                      $options['deleteTop']= $this->getOption('skipDirs', $options, false) ? false : $this->getOption('deleteTop', $options, false);
                      if ($this->getOption('deleteTop', $options, false)) {
                          if (@ rmdir($dirname)) {
                              array_push($result, $dirname);
                          }
                      }
                  }
              } else {
                  $result= false; /* return false if attempting to operate on a file */
              }
              return $result;
          }
      


      Many thanks in advance!
      Letti
        • 11055 ☆ A M B ☆
        • 3,112 Posts
        probably you would be interested to post this into the http://bugs.modx.com, including your newsletter script.
          Rico
          Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
          MODx is great, but knowing how to use it well makes it perfect!

          www.virtudraft.com

          Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

          Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

          Maintainter/contributor of Babel

          Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
          • 17016
          • 138 Posts
          Thanks for your reply. One additional remark: The newsletter was only the reason for much traffic at the same time on our server. The newsletter itself had no content which could interfere with the websites...

          Letti
            • 17016
            • 138 Posts
            We now posted the problem in the bug-reports.

            Although we got many of these errors we don´t know in which situations these two errors-messages occur.

            (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 413) PHP warning: unlink(/server/modx/core/cache/objects/modTemplateVarResource/2c3468c42bcf1c299e5839accdace0ea.cache.php) [<a href='function.unlink'>function.unlink</a>]: No such file or directory
            
            (ERROR @ /server/modx/core/xpdo/cache/xpdocachemanager.class.php : 421) PHP warning: closedir(): 413 is not a valid Directory resource
            


            Does anybody know in which situations the code-snipped mentionend above becomes active? It is labeled as "Recursively deletes a directory tree of files"

            Maybe we can somehow avoid to become this code-snipped active by putting certain websites offline which might cause these errors...
              • 21838
              • 284 Posts
              For me it seems you have some file permissions not configured correct...?
              Can you reproduce it (look to date in error log and consider what you’ve done)?
                MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
                • 17016
                • 138 Posts
                Quote from: smooth-graphics at Dec 21, 2010, 05:41 AM

                For me it seems you have some file permissions not configured correct...?
                Yes. That´s a really good point. In the beginning we did some changes in the CHMOD-Configuration of many folders because we were afraid of don´t having a system safe enough. Meanwhile we figured out that we even need 777 for example for the folder "assets/components" to make the package-installations work properly. Otherwise we cannot update packages although our server-admin told us never give 777 to folders. Maybe some folders or files still need more rights. Do you have any idea which folders maybe need more rights?

                Quote from: smooth-graphics at Dec 21, 2010, 05:41 AM

                Can you reproduce it (look to date in error log and consider what you’ve done)?
                That´s exactly the problem. We have about 2.000 visitors each day on our website leading to these errors once in a while. But we never managed to provoke these errors artificially or by ourselves.
                  • 21838
                  • 284 Posts
                  Okay, I’m still more on wrong file permissions as you’ve said you "need" CHMOD777.
                  I don’t know any provider where CHMOD 777 works correct with directories.

                  Please change writable directories to 755 and files that need to be writbale to 777 (which is in fact nearly no one in MODx). Normally files get a 666 or better 644 CHMOD.
                    MODX Free Template Base: MODX-Boilerplate | my blog (lots of MODX stuff) | my gitHub (translations) | MODX User Groups Germany (Facebook)
                    • 17016
                    • 138 Posts
                    We are now able to reproduce the error. The errors always appear if three or more different webpages are visited at the same time for the first time after clearing the cache. If a site is once cached this site makes no problems anymore. The CHMODs are meanwhile corrected by us to the original values and the system is upgraded from 2.0.5 to 2.0.6.

                    Does anybody has an idea what could be the reason for this? The two error are always:

                    (ERROR @ .../modx/core/xpdo/cache/xpdocachemanager.class.php : 413) PHP warning: unlink(.../modx/core/cache/objects/modTemplateVar/beb4dbf9af069aa2df7b147229965085.cache.php) [<a href='function.unlink'>function.unlink</a>]: No such file or directory
                    
                    (ERROR @ .../modx/core/xpdo/cache/xpdocachemanager.class.php : 421) PHP warning: closedir(): 109 is not a valid Directory resource
                    

                    (the number "109" of the second error is changing each time)

                    Are there any php-settings of our server of interest? Maybe it is a misconfiguration of our server? Some of our settings are:
                    PDO Driver for MySQL, client library version: 5.1.49
                    PDO support: enabled
                    max_execution_time: 30
                    memory_limit	128M
                    APC-Cache is activated
                    

                      • 17016
                      • 138 Posts
                      If some of the MODx-founders read this thread: Is it possible to get commercial support for this problem?

                      Letti