Falk S.
Falk S.

Reputation: 142

PHP recursive call is causing an interal server error

i was programming a mail templatingsystem. The user should be able to use markers in there, they will be replaced by the actual data. The problem ist, my function to replace the markers works just fine, but i need to do a recursiv call of that function, that will only run once, and this is what i came up with:

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

The recursiv call in this line

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

is causing a 500 internal server error. I dont know why, because i think that i limited the recursion to run once. Can you help me out?

Sorry for my bad english i try hard to write clear sentences.

//EDIT:

Apache log:

[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 

the php errorlog is empty.

Upvotes: 1

Views: 1104

Answers (2)

lfxgroove
lfxgroove

Reputation: 3908

It would seem you miss one argument in your recursive call, making the $recursive = false continue being false all the time, which in turn makes your if statement

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

always return true. Try adding one last variable to your recursive call instead and you should be able to properly execute your script, ie:

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

What i think you want to add instead of the first true is $format.

Upvotes: 1

ThiefMaster
ThiefMaster

Reputation: 318508

Signal 11 is SIGSEGV, i.e. the process crashed due to a bad memory access (such as dereferencing a NULL pointer or accessing memory it was not supposed to access).

This is nothing a PHP script should be causing, so you should first upgrade to the most recent stable PHP version and if it still happens reduce your script as much as possible (remove everything that can be removed while the crash still happens) and then report it as a PHP bug.

Upvotes: 0

Related Questions