1

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.

pnuts
59.7k11 gold badges92 silver badges141 bronze badges
asked May 31, 2012 at 7:30
4
  • 2
    Pleas look at server logs for more detailed error message. Commented May 31, 2012 at 7:32
  • 1
    You may want to look at the line if($this->need_replacement($content, 'weiterempfehlung') === false && $recursion === false) { as it seems that your IF statement is returning true everytime, resulting in the script never stopping until PHP dies on either the script execution timeout or lack of memory. Commented May 31, 2012 at 7:39
  • as you can see in the if case the recursiv call is done with an extra param $recursion === true, which will be checked in the if statement, with that it should be not possible to loop Commented May 31, 2012 at 7:44
  • Check my answer, you've forgot one parameter to your function resulting in it being false all the time. Commented May 31, 2012 at 8:09

2 Answers 2

1

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.

answered May 31, 2012 at 7:57
1
  • you are such a genius!! Thank you so much, i was looking for so long how can i be that dumb. Commented May 31, 2012 at 8:12
0

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.

answered May 31, 2012 at 7:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.