Drupal 7 PHP内存耗尽问题求助:调大内存仍报错
初始4G内存限制下的报错日志
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 28672 bytes) in /home/....com/public_html/.../includes/cache.inc on line 361
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 262144 bytes) in /home/....com/public_html/.../includes/database/database.inc on line 731
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 16384 bytes) in /home/....com/public_html/.../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 16384 bytes) in /home/....com/public_html/.../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 16384 bytes) in /home/....com/public_html/.../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 20480 bytes) in /home/....com/public_html/.../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 16384 bytes) in /home/....com/public_html/.../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 4294967296 bytes exhausted (tried to allocate 32768 bytes) in /home/....com/public_html/.../includes/database/database.inc on line 2284
报错相关代码片段
cache.inc 第361行所在函数
# function contains line 361 function getMultiple(&$cids) { try { // Garbage collection necessary when enforcing a minimum cache lifetime. $this->garbageCollection($this->bin); // When serving cached pages, the overhead of using db_select() was found // to add around 30% overhead to the request. Since $this->bin is a // variable, this means the call to db_query() here uses a concatenated // string. This is highly discouraged under any other circumstances, and // is used here only due to the performance overhead we would incur // otherwise. When serving an uncached page, the overhead of using // db_select() is a much smaller proportion of the request. $result = db_query('SELECT cid, data, created, expire, serialized FROM {' . db_escape_table($this->bin) . '} WHERE cid IN (:cids)', array(':cids' => $cids)); $cache = array(); // #361 foreach ($result as $item) { $item = $this->prepareItem($item); if ($item) { $cache[$item->cid] = $item; } } $cids = array_diff($cids, array_keys($cache)); return $cache; } catch (Exception $e) { // If the database is never going to be available, cache requests should // return FALSE in order to allow exception handling to occur. return array(); } }
cache.inc 第449行所在函数
#function contains line 449 protected function prepareItem($cache) { global $user; if (!isset($cache->data)) { return FALSE; } // If the cached data is temporary and subject to a per-user minimum // lifetime, compare the cache entry timestamp with the user session // cache_expiration timestamp. If the cache entry is too old, ignore it. if ($cache->expire != CACHE_PERMANENT && variable_get('cache_lifetime', 0) && isset($_SESSION['cache_expiration'][$this->bin]) && $_SESSION['cache_expiration'][$this->bin] > $cache->created) { // Ignore cache data that is too old and thus not valid for this user. return FALSE; } // If the data is permanent or not subject to a minimum cache lifetime, // unserialize and return the cached data. //#449 if ($cache->serialized) { $cache->data = unserialize($cache->data); } return $cache; }
当前环境配置
PHP version: 7.4.33 PHP memory_limit: 4G PHP post_max_size: 16M PHP upload_max_filesize: 4M PHP max_input_vars: 1000 PHP max_execution_time: 60 OS: Almalinux 9 webserver: Apache Drupal version: V 7.101
调整内存限制到7G后的报错日志
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 32768 bytes) in /home/.....com/public_html/..../includes/cache.inc on line 361
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 20480 bytes) in /home/.....com/public_html/..../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 20480 bytes) in /home/.....com/public_html/..../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 20480 bytes) in /home/.....com/public_html/..../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 20480 bytes) in /home/.....com/public_html/..../includes/cache.inc on line 449
PHP Fatal error: Allowed memory size of 7516192768 bytes exhausted (tried to allocate 262144 bytes) in /home/.....com/public_html/..../includes/database/database.inc on line 731
求助说明
不清楚错误根源,调整memory_limit到7G仍无法解决问题,曾设置memory_limit = -1导致服务器24小时后崩溃,求排查方向。
内容的提问来源于stack exchange,提问作者hoangvnn

