2012-05-31 85 views
1

我正在編寫郵件模板系統。用戶應該能夠在那裏使用標記,它們將被實際數據替代。問題IST,我的函數替換標記工作得很好,但我需要做的功能,這將只運行一次的recursiv通話,這就是我想出了:PHP遞歸調用導致內部服務器錯誤

public function replace_placeholders($content, $recipient, $settings, $interface, $recommendation, $format, $recursion = false) { 
    $content = $this->replace_ph('briefanrede' , $recipient['id']   , $content); 
    $content = $this->replace_ph('anrede'  , $recipient['title']  , $content); 
    $content = $this->replace_ph('email'  , $recipient['email']  , $content); 
    $content = $this->replace_ph('kundennummer' , $recipient['kdnumber'] , $content); 
    $content = $this->replace_ph('briefanrede' , $recipient['briefanrede'] , $content); 

    if($recipient['title'] == $settings['anrede_w'] || $recipient['title'] == $settings['anrede_m']) { 
     $content = $this->replace_ph('vorname' , $recipient['forename'] , $content); 
     $content = $this->replace_ph('nachname' , $recipient['surename'] , $content); 
    } else { 
     $content = $this->replace_ph('vorname' , "" , $content, true); 
     $content = $this->replace_ph('nachname' , "" , $content, true); 
    } 

    $content = $this->replace_salutation($recipient, $settings, $content); 

    //Recommendation  
    if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) { 
     if($recommendation['own_page'] == 1) { 
      $baseurl = $recommendation['location']; 
     } else { 
      $baseurl = $recommendation['link']; 
     } 
     $pattern = ($format == "html") ? '<a href="%s">%s</a>' : '%s'; 
     $url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true); 
     $content = $this->replace_ph('weiterempfehlung' , (($format == "html") ? sprintf($pattern, $url, $settings['text_weiterempfehlung']): sprinf($pattern, $url)), $content); 

    } 

    return $content; 
} 

的recursiv請致電此行

$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, $recommendation, true); 

導致500內部服務器錯誤。我不知道爲什麼,因爲我認爲我限制遞歸運行一次。你能幫我嗎?

對不起我英語不好我努力寫出明確的句子。

//編輯:

Apache日誌:

[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: error reading data from FastCGI server 
[Wed May 30 15:31:56 2012] [warn] [client xx.xxx.xx.xxx] (104)Connection reset by peer: mod_fcgid: ap_pass_brigade failed in handle_request_ipc function 
[Wed May 30 15:31:56 2012] [error] [client xx.xxx.xx.xxx] File does not exist: /var/www/web80/html/web80-newsletter/favicon.ico 
[Wed May 30 15:31:58 2012] [error] mod_fcgid: process /var/www/php-fcgi/web80.php53/php-fcgi(21975) exit(communication error), get unexpected signal 11 

的PHP錯誤日誌是空的。

+2

請仔細查看服務器日誌以獲取更詳細的錯誤消息。 –

+1

你可能想看看if($ this-> need_replacement($ content,'weiterempfehlung')=== false && $ recursion === false){'因爲看起來你的IF語句每次都返回true ,導致腳本永遠不會停止,直到PHP死於腳本執行超時或內存不足。 – Gavin

+0

你可以看到在if情況下,recursiv調用是通過一個額外的參數$ recursion === true來完成的,它將在if語句中檢查,並且它不應該循環 –

回答

1

這似乎你錯過了一個參數在你的遞歸調用,使得$recursive = false繼續成爲假所有的時間,這反過來又使你的if語句

if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) 

始終返回true。 嘗試添加一個最後一個變量到您的遞歸調用,而不是和你應該能夠正確地執行你的腳本,即:

$url = $this->replace_placeholders($baseurl, $recipient, $settings, $interface, 
$recommendation, true, true); 
        ^added one true 

什麼,我想你想添加的,而不是第一個真正爲$format

+0

你是如此的天才!非常感謝你,我一直在尋找那麼久,我怎麼會這麼愚蠢。 –

+0

我自己也犯過同樣的錯誤;) – lfxgroove

0

信號11是SIGSEGV,即進程因存儲器訪問不良而崩潰(如取消引用NULL指針或訪問它不應訪問的存儲器)。

這不是PHP腳本應該導致的問題,所以您應該先升級到最新的穩定PHP版本,如果它仍然發生,儘可能減少腳本(刪除所有可以在崩潰發生時刪除的腳本),然後將其報告爲PHP錯誤。

相關問題