doddsey_65 Posted June 27, 2011 Share Posted June 27, 2011 My site runs quite slowly compared to others and im wondering if its the use of preg_replace in my template class. For example in my html page i would have [$root] which would be replaced by the template class using preg replace to the document root. This is just an example, i have loads more rules which replace stuff like that. So is preg_replace slow or are there other reasons why my site is slow? Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/ Share on other sites More sharing options...
AMcHarg Posted June 27, 2011 Share Posted June 27, 2011 Why not remove it and see if it makes your site run more quickly? If it does then you can be sure that it was the problem. Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235328 Share on other sites More sharing options...
doddsey_65 Posted June 27, 2011 Author Share Posted June 27, 2011 if i remove the preg replace several needed things wont load and therefore break the site. Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235333 Share on other sites More sharing options...
TeNDoLLA Posted June 27, 2011 Share Posted June 27, 2011 There is some comparison for possible choices: http://www.php-scripts.com/php_diary/011303.php3 . Also if you dont have zillion of replaces I think its something else that is slowing down your site. Maybe you have some loops which makes some useless replaces many times or something like that? Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235335 Share on other sites More sharing options...
salathe Posted June 27, 2011 Share Posted June 27, 2011 So is preg_replace slow or are there other reasons why my site is slow? The function may be "slow" depending on the regular expression and replacements being made, though in most normal cases it is not "slow" at all. Have a look at profiling your script (search "xhprof", "xdebug") to find out really where the slow parts of the script lie, rather than guessing. Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235341 Share on other sites More sharing options...
doddsey_65 Posted June 27, 2011 Author Share Posted June 27, 2011 could it be then the inclusion of html files? for example, to return a list of the forums i run code which returns one html file and loop it for however many forums there is. example of the included file: {FORUM_NAME} then i loop to render the forum name of each forum. Could this be it since some of the html files which are looped consist of around 200 lines of html. Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235519 Share on other sites More sharing options...
salathe Posted June 28, 2011 Share Posted June 28, 2011 Have a look at profiling your script (search "xhprof", "xdebug") to find out really where the slow parts of the script lie, rather than guessing. Quote Link to comment https://forums.phpfreaks.com/topic/240509-preg_replace/#findComment-1235763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.