0

I have written a small code to check the speed of my server. BUt it takes almost 60 seconds to finish execution.

<?php


     $start=time();

     $to = "test@gmail.com";

     $subject = "This is subject";

     $message = "<b>This is HTML message.</b>";
     $message .= "<h1>This is headline.</h1>";

     $header = "From:test@mydomain.com \r\n";
     $header .= "MIME-Version: 1.0\r\n";
     $header .= "Content-type: text/html\r\n";

     $retval = mail ($to,$subject,$message,$header);

     if( $retval == true ) {
        echo "Message sent successfully...";
     }else {
        echo "Message could not be sent...";
     }

     $after=time();
     $total=$after-$start;
     echo "</br>";
     echo "Total execution time : ".$total." seconds";
?>

What maybe the reason? and how can I improve the execution time? I already increased the memory limit in php.ini file.

alex_gabriel
  • 373
  • 1
  • 8
  • 20
  • And is it completely executed ? Do you receive the email ? Could you check your logs, there is maybe a blocking firewall, a error with the DNS or a usable message in apache log – Dom Jun 22 '16 at 07:13
  • @Dom: It was an issue with the sendmail service in the server. I installed postfix and now its way much faster. It was 60 seconds with sendmail..Now it takes just 1 second.. – alex_gabriel Jun 24 '16 at 10:59
  • The best way to figure out why a script takes a long time is to use profiling or logging in the script. It is a programming question, not an email or linux question. – Jenny D Jun 28 '16 at 09:18

1 Answers1

0

It was an issue with sendmail mailserver. Installing postfix mailserver solved the issue.

alex_gabriel
  • 373
  • 1
  • 8
  • 20