Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP script performance issue
    text
    copied!<p>There seems to be a performance issue with the script as it is really slow. I was wondering what I could do to speed this up. If you have any ideas, please let me know. I can't seem to figure it out.</p> <p>Below is the code:</p> <pre><code>&lt;?php include_once("connect.php.inc"); class HtmlEnc{ static function uniord($c) { $ud = 0; if (ord($c{0}) &gt;= 0 &amp;&amp; ord($c{0}) &lt;= 127) $ud = ord($c{0}); if (ord($c{0}) &gt;= 192 &amp;&amp; ord($c{0}) &lt;= 223) $ud = (ord($c{0})-192)*64 + (ord($c{1})-128); if (ord($c{0}) &gt;= 224 &amp;&amp; ord($c{0}) &lt;= 239) $ud = (ord($c{0})-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); if (ord($c{0}) &gt;= 240 &amp;&amp; ord($c{0}) &lt;= 247) $ud = (ord($c{0})-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); if (ord($c{0}) &gt;= 248 &amp;&amp; ord($c{0}) &lt;= 251) $ud = (ord($c{0})-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); if (ord($c{0}) &gt;= 252 &amp;&amp; ord($c{0}) &lt;= 253) $ud = (ord($c{0})-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); if (ord($c{0}) &gt;= 254 &amp;&amp; ord($c{0}) &lt;= 255) $ud = false; // error return $ud; } static function toHtml($str){ $html_str = ""; while (strlen($str) &gt; 0) { preg_match("/^(.)(.*)$/u", $str, $match); $test = utf8_decode($match[1]); if ($test != "?") { $html_str .= htmlentities(htmlentities($test)); } else if (strlen($match[1]) &gt; 1) { $html_str .= "&amp;amp;#".self::uniord($match[1]).";"; } else $html_str .= htmlentities(htmlentities($match[1])); $str = $match[2]; } return $html_str; } } /* List of mail servers */ function alreadyDone($domain){ $domain = strtolower($domain); $qry = "SELECT * FROM emdb WHERE domain ='" . $domain . "'"; $result = mysql_query($qry); return (mysql_num_rows($result)!=0); } $template_fn = $_REQUEST['template']; //"mail_template.html"; $keywords = HtmlEnc::toHtml($_REQUEST['Keywords']); $keywords = str_replace("&amp;amp;","&amp;",$keywords); $domain = $_REQUEST['Domain']; $rank = $_REQUEST['Rank']; $to = $_REQUEST['Email']; $adminEmail = "test@example.com"; if (!alreadyDone($domain)) { if ($to=="") { $to = "info@" . $domain; } function int_divide($x, $y) { if ($x == 0) return 0; if ($y == 0) return FALSE; return ($x - ($x % $y)) / $y; } $page = int_divide($rank,10) + 1; if ($template_fn == "mail_template_nick.html" || $template_fn == "mail_template_chet.html" || "mail_template_salesperson.php") $subject = $domain." is on Page ".$page." of Google - Want to be #1?"; elseif ($template_fn == "seo_template.html") $subject = "Outsource your SEO - Lowest rates guaranteed!"; elseif ($template_fn == "adwords_template.html") $subject = $domain . " - Save your money on Google Adwords"; else $subject = $domain . " is ranked " . $rank . " on Google - Be 1st!"; $message = file_get_contents($template_fn); /*$message = "&lt;body&gt; &lt;p&gt;Hi There,&lt;/p&gt; &lt;p&gt;How's your week been so far?&lt;/p&gt; &lt;p&gt;When I Googled &amp;quot;{KEYWORD}&amp;quot;, I found {WEBSITE} on page {PAGE}, not on page 1. This means consumers will find your competitors before they find you!&lt;/p&gt; &lt;p&gt;93% of all people, never go past the 1st page of Google, so at this very moment you're losing sales &amp;amp; leads to a competitor. &lt;/p&gt; &lt;p&gt;If you agree your Google exposure needs drastic improvement, please call me for a chat, I'm sure I can give some good, free advice. &lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Best Regards,&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Kayne Chong &lt;/strong&gt;&lt;strong&gt;- Business Development Director&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Tel:&lt;/strong&gt;&amp;nbsp; | &amp;nbsp;&lt;strong&gt;Fax:&amp;nbsp;&lt;/strong&gt;&lt;br /&gt; &lt;strong&gt;Office:&lt;/strong&gt;&amp;nbsp;&lt;br /&gt; &lt;strong&gt;Web:&lt;/strong&gt;&amp;nbsp;&lt;a href='http://www.seoagency.com.sg/' target='_blank'&gt;&lt;em&gt;www.seoagency.com.sg&lt;/em&gt;&lt;/a&gt;&lt;br /&gt; &lt;strong&gt;&lt;em&gt;Web marketing that brings BUSINESS to you!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt; &lt;/body&gt;";*/ $message = str_replace("{WEBSITE}", $domain , $message); $message = str_replace("{PAGE}", $page , $message); //$message = str_replace("{RANK}", $rank , $message); $message = str_replace("{KEYWORD}", $keywords , $message); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers /*$headers .= 'Bcc: ' . $adminEmail . "\r\n"; if ($template_fn == "mail_template_salesperson.php") { $headers .= 'From: Kayne - Web Marketing Experts &lt;test@example.com&gt;' . "\r\n"; $headers .= 'Reply-To: test@example.com' . "\r\n";} elseif ($template_fn == "mail_template_chet.html") { $headers .= 'From: Chester - Web Marketing Experts &lt;test@example.com&gt;' . "\r\n"; $headers .= 'Reply-To: test@example.com' . "\r\n";}*/ $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Bcc: ' . $adminEmail . "\r\n"; $headers .= 'From: Info - Web Marketing Experts &lt;test@example.com&gt;' . "\r\n"; $headers .= 'Reply-To: test@example.com' . "\r\n"; if (mail($to, $subject, $message, $headers)) { echo "Mail successfully sent to $to and $adminEmail"; } else echo "Mail sending failed!"; $qry = "INSERT INTO emdb (domain, keywords, rank, last, count) VALUES ('$domain','$keywords','$rank',CURDATE(), '1')"; mysql_query($qry) or die(mysql_error()); echo "&lt;BR /&gt;"; echo "DB updated"; } else { echo "Domain name $domain has already been processed"; } ?&gt; </code></pre> <p>Thank you. Jae</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload