PHP 递归调用导致服务器间错误


PHP recursive call is causing an interal server error

我正在编写一个邮件模板系统。用户应该能够在那里使用标记,它们将被实际数据替换。问题是,我替换标记的函数工作得很好,但我需要对该函数进行递归调用,它只会运行一次,这就是我想出的:

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;
}

此行中的递归调用

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

导致 500 内部服务器错误。我不知道为什么,因为我认为我将递归限制为运行一次。你能帮我吗?

对不起,我的英语不好,我努力写出清晰的句子。

//编辑:

阿帕奇日志:

[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 错误日志为空。

您似乎在递归调用中错过了一个参数,使$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

我认为您要添加而不是第一个 true 的是 $format .

信号

11 是 SIGSEGV,即进程由于错误的内存访问(例如取消引用空指针或访问它不应该访问的内存)而崩溃。

这不是 PHP 脚本

应该造成的,所以你应该首先升级到最新的稳定 PHP 版本,如果它仍然发生,尽可能减少你的脚本(删除所有可以删除的崩溃仍然发生),然后将其报告为 PHP 错误。