Due to the risk of redirecting to this answer (yes, I read it and spent the last 5 minutes laughing out loud at it), let me explain this problem, which is just one of many.
My employer asked me to look at a site written in PHP using Smarty for templates and MySQL as a DBMS. Currently, it works very slowly, taking up to 2 minutes (with a completely white screen through it all, no less) for a full load.
Profiling the code with xdebug, I found one call to preg_replace, which takes about 30 seconds to complete, which currently goes through all the HTML code and replaces every URL found in its SEO-friendly version. Once it completes, it will output all the code to the browser. (As I said, this is not the only question - the code is quite old and it shows, but I will focus on it for this question.)
Digging further into the code, I found that it is currently scanning 1702 patterns with each matching match (both matches and replacements in arrays of the same size), which certainly takes into account the time it takes.
The code is as follows:
$seourls_data = $oSeoShared->getSeourls();
$url_masks = array();
$seourls = array();
foreach ($seourls_data as $seourl_data)
{
if ($seourl_data["url"])
{
$url_masks[] = "/([\"'\>\s]{1})".$site.str_replace("/", "\/", $seourl_data["url"])."([\#|\"'\s]{1})/";
$seourls[] = "$1".MAINSITE_URL.$seourl_data["seourl"]."$2";
}
}
$html_seo = preg_replace($url_masks, $seourls, $html);
: HTML . , ? , , :
- (, ) HTML DOMDocument, href .
- node, URL-, (, , , )
- ???
- Profit?
, .
?
.