我正在編寫郵件模板系統。用戶應該能夠在那裏使用標記,它們將被實際數據替代。問題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錯誤日誌是空的。
請仔細查看服務器日誌以獲取更詳細的錯誤消息。 –
你可能想看看if($ this-> need_replacement($ content,'weiterempfehlung')=== false && $ recursion === false){'因爲看起來你的IF語句每次都返回true ,導致腳本永遠不會停止,直到PHP死於腳本執行超時或內存不足。 – Gavin
你可以看到在if情況下,recursiv調用是通過一個額外的參數$ recursion === true來完成的,它將在if語句中檢查,並且它不應該循環 –