2013-04-02 49 views
0

我的虛擬專用服務器出現問題。 VPS主辦2個WordPress的網站。 自上週以來,服務器突然開始有時會產生錯誤,並且兩個網站在前端顯示下面的錯誤。重新啓動Apache網絡服務器後,它可以再次運行1或2天,但這次似乎正在減少。爲foreach提供的無效參數 - 建立數據庫連接時出錯

這是在前端產生的錯誤是:

"Warning: Invalid argument supplied for foreach() in /var/www/html/domainname/wp-includes/locale.php on line 117 Warning: Invalid argument supplied for foreach() in /var/www/html/domainname/wp-includes/locale.php on line 159 Error establishing a database connection"

Locale.php的內容:(什麼也沒有改變這個)

function init() { 
    // The Weekdays 
    $this->weekday[0] = /* translators: weekday */ __('Sunday'); 
    $this->weekday[1] = /* translators: weekday */ __('Monday'); 
    $this->weekday[2] = /* translators: weekday */ __('Tuesday'); 
    $this->weekday[3] = /* translators: weekday */ __('Wednesday'); 
    $this->weekday[4] = /* translators: weekday */ __('Thursday'); 
    $this->weekday[5] = /* translators: weekday */ __('Friday'); 
    $this->weekday[6] = /* translators: weekday */ __('Saturday'); 

    // The first letter of each day. The _%day%_initial suffix is a hack to make 
    // sure the day initials are unique. 
    $this->weekday_initial[__('Sunday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Sunday_initial'); 
    $this->weekday_initial[__('Monday')] = /* translators: one-letter abbreviation of the weekday */ __('M_Monday_initial'); 
    $this->weekday_initial[__('Tuesday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Tuesday_initial'); 
    $this->weekday_initial[__('Wednesday')] = /* translators: one-letter abbreviation of the weekday */ __('W_Wednesday_initial'); 
    $this->weekday_initial[__('Thursday')] = /* translators: one-letter abbreviation of the weekday */ __('T_Thursday_initial'); 
    $this->weekday_initial[__('Friday')] = /* translators: one-letter abbreviation of the weekday */ __('F_Friday_initial'); 
    $this->weekday_initial[__('Saturday')] = /* translators: one-letter abbreviation of the weekday */ __('S_Saturday_initial'); 

    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) { 
     $this->weekday_initial[$weekday_] = preg_replace('/_.+_initial$/', '', $weekday_initial_); 
    } 

    // Abbreviations for each day. 
    $this->weekday_abbrev[__('Sunday')] = /* translators: three-letter abbreviation of the weekday */ __('Sun'); 
    $this->weekday_abbrev[__('Monday')] = /* translators: three-letter abbreviation of the weekday */ __('Mon'); 
    $this->weekday_abbrev[__('Tuesday')] = /* translators: three-letter abbreviation of the weekday */ __('Tue'); 
    $this->weekday_abbrev[__('Wednesday')] = /* translators: three-letter abbreviation of the weekday */ __('Wed'); 
    $this->weekday_abbrev[__('Thursday')] = /* translators: three-letter abbreviation of the weekday */ __('Thu'); 
    $this->weekday_abbrev[__('Friday')] = /* translators: three-letter abbreviation of the weekday */ __('Fri'); 
    $this->weekday_abbrev[__('Saturday')] = /* translators: three-letter abbreviation of the weekday */ __('Sat'); 

    // The Months 
    $this->month['01'] = /* translators: month name */ __('January'); 
    $this->month['02'] = /* translators: month name */ __('February'); 
    $this->month['03'] = /* translators: month name */ __('March'); 
    $this->month['04'] = /* translators: month name */ __('April'); 
    $this->month['05'] = /* translators: month name */ __('May'); 
    $this->month['06'] = /* translators: month name */ __('June'); 
    $this->month['07'] = /* translators: month name */ __('July'); 
    $this->month['08'] = /* translators: month name */ __('August'); 
    $this->month['09'] = /* translators: month name */ __('September'); 
    $this->month['10'] = /* translators: month name */ __('October'); 
    $this->month['11'] = /* translators: month name */ __('November'); 
    $this->month['12'] = /* translators: month name */ __('December'); 

    // Abbreviations for each month. Uses the same hack as above to get around the 
    // 'May' duplication. 
    $this->month_abbrev[__('January')] = /* translators: three-letter abbreviation of the month */ __('Jan_January_abbreviation'); 
    $this->month_abbrev[__('February')] = /* translators: three-letter abbreviation of the month */ __('Feb_February_abbreviation'); 
    $this->month_abbrev[__('March')] = /* translators: three-letter abbreviation of the month */ __('Mar_March_abbreviation'); 
    $this->month_abbrev[__('April')] = /* translators: three-letter abbreviation of the month */ __('Apr_April_abbreviation'); 
    $this->month_abbrev[__('May')] = /* translators: three-letter abbreviation of the month */ __('May_May_abbreviation'); 
    $this->month_abbrev[__('June')] = /* translators: three-letter abbreviation of the month */ __('Jun_June_abbreviation'); 
    $this->month_abbrev[__('July')] = /* translators: three-letter abbreviation of the month */ __('Jul_July_abbreviation'); 
    $this->month_abbrev[__('August')] = /* translators: three-letter abbreviation of the month */ __('Aug_August_abbreviation'); 
    $this->month_abbrev[__('September')] = /* translators: three-letter abbreviation of the month */ __('Sep_September_abbreviation'); 
    $this->month_abbrev[__('October')] = /* translators: three-letter abbreviation of the month */ __('Oct_October_abbreviation'); 
    $this->month_abbrev[__('November')] = /* translators: three-letter abbreviation of the month */ __('Nov_November_abbreviation'); 
    $this->month_abbrev[__('December')] = /* translators: three-letter abbreviation of the month */ __('Dec_December_abbreviation'); 

    foreach ($this->month_abbrev as $month_ => $month_abbrev_) { 
     $this->month_abbrev[$month_] = preg_replace('/_.+_abbreviation$/', '', $month_abbrev_); 
    } 

我沒有改變在php或mysql配置中的任何東西,我不知道爲什麼它開始表現得像這樣。

臨時解決方案是重新啓動httpd服務,然後一切都將罰款約1天,但似乎這次減少到有時一個半小時。

起初我以爲這個問題是由Mysql造成的。不過,我配置了一個測試工具來測試mysql。在VPS遇到問題時,通過Mysql testtool登錄到數據庫時沒有問題。

說實話,我不是PHP大師,希望有人能讓我走上正軌。我一直在解決和瀏覽論壇幾個小時,但現在我不知道如何解決它。

如果您需要更多信息,請詢問。 非常感謝提前。

最好的問候, 羅伯特

回答

2

嘗試檢查他們的是他們是數組或之前沒有像

if(is_array($this->weekday_initial)) 
    foreach ($this->weekday_initial as $weekday_ => $weekday_initial_) 
+0

循環「警告:提供的foreach()無效參數」是指我們是否已通過非數組或它可能是數據庫問題... – Gautam3164

+0

嗨,謝謝。 我該如何檢查? – user2235385

+0

首先檢查選擇功能,從中獲取數據....然後查詢和參數傳遞....還回顯您的SQL查詢並在您的數據庫中運行它,如果結果不來,那麼有問題您的查詢 – Gautam3164