Hi,
Since a couple of days in noticed that my website is very slow when not serving cached pages of when caching is disabled. I’ve narrowed the problem down to a plugin and a custom function in functions.php that make (js) calls to social media api’s to count the amount of social media shares for each post on the website. These two “plugins” result in a very slow website and a slow cached page generation. I’m running on a VPS (with enough resources, it’s little overpowered) with Plesk 11 which uses Nginx as a reverse proxy. Nginx handles all PHP, static files and is configured to work with WP Super Cache to serve compressed cached pages.
The problem I encounter with these two “plugins” is that the generation of dynamic cached pages take more than 20 seconds in some cases, which normally only took less than a second, a couple of seconds at worst. Also, the time to first byte can take up to 6 seconds, instead of the less than 1 second which is normal.
Without caching is disabled, the page will still load very slowly, as if the rendering only starts when those javascripts are handled. I know this isn’t exactly theme related, but i’ve read somewhere in another post that it’s possible to move the plugins javascripts and css to the footer by using the wp-booster plugin.
I now know what causes the problem, but i don’t exactly how. I’m desperate for a solution and hope someone can help me!
-
This topic was modified 12 years by
r1kay.
hi,
we created wp-booster plugin to have a bigger google pagespeed result, what it duos, is moving the css and javascript files in the footer of the page.
the bad news about wp-booster plugin is that is known to make the theme not function properly, an issue we are still investigate. also is compatible with only a couple of plugins (wp supper cache, Seo by Yost, tagDiv social counter).
my advise is to disable all the plugins but WP Super Cache, tagDiv social counter, contact 7. it should work.
Thanks for you message.
Radu A.
Disabling all plugins isn’t an option. I need most of them to make my website work. I was just wondering if it is something theme related or wordpress related. Maybe the theme is set up to load all external js before rendering the page? And if not, how can i make the page render before those scripts are loaded? Also, the wp-postview and ajax vies count plugins slow down the rendering of the page! Are you guys planning on integrating these ajax views counters in the next update? I would be nice to so the theme functions working flawlessly with caching plugins. I mean, that is what you guys advertise with: the theme’s speed and functionality 🙂
Love to hear some opions from other people and would like to know if somebody else is experiencing the same problem with plugins or functions that make js calls to social media api! I can’t be the only one who uses plugins that show how many times a post is shared on social media.
Anything that connects to multiple external systems and has to get a response will slow down the site; everything like recaptcha, jetpack, adsense, social plugins which “go out an get data and then bring it back to cache” and similar — all slow things down since it’s not happening “locally.” (As I’m sure you already know.) You would likely disable the theme’s function to “count” reads/shares from other sites, and try using something like AddThis which can also do this for you. Ironically, the reason the calls to the APIs in the functions.php is done to avoid having to use external plugins and for most of us makes site run faster than using external plugs. But every site is different, and part of the development process is picking/choosing how to add/adjust things on page for best user experience and performance.
Note also that WP-Postview was updated this week to address issues folks were having with Ajax and Cache, so might be worth revisiting that setup with new version.
Not sure if that helped at all, but my two cents.
Well i use the sharedcount api to count the total shares for me. It´s considered one of the fastest api to do this. Maybe i have configured the function wrong, i´ve tested it without caching and this peace of code make the website render at least 3 seconds later. Maybe you can have a look:
function getTotalShares($atts) {
extract(shortcode_atts(array(
'cache' => '600',
'url' => 0,
'f' => 0,
'bgcolor' => '#7bc6f1',
'bordercolor' => '#000',
'borderwidth' => '0',
'bordertype' => 'solid',
'fontcolor' => '#fff',
'fontsize' => '18',
'fontweight' => 'normal',
'padding' => '1',
'fontfamily' => 'Oswald'
), $atts));
$shareHash = "$cache.$url.$f.$bgcolor.$bordercolor.$borderwidth.$bordertype.$fontcolor.$fontsize.$fontweight.$padding.$fontfamily";
$totalShareRecord = 'totalshares_' . $shareHash;
$cachedposts = get_transient($totalShareRecord);
if ($cachedposts !== false) {
return $cachedposts;
} else {
if (!$url) $url = get_permalink($post->ID);
$json = wp_remote_retrieve_body( wp_remote_get("http://api.sharedcount.com/?url=" . rawurlencode($url) . "&apikey=0928d3131a18a15945e4c74fa1a68cef3c6f2ad8"));
$counts = json_decode($json, true);
$return = $counts['Twitter'] + $counts['Facebook']['total_count'] + $counts['GooglePlusOne'];
if ($f) $return = '<div id="totalshares"><img src="http://mhmag.nl/content/uploads/2014/04/viral-icon-retina-42-x-42.png" width="21" height="21" /><div id="sharecounter">' . $return . '</div><div id="gedeeld">x gedeeld</div></div>';
set_transient($totalShareRecord, $return, $cache);
return $return;
}
}
add_shortcode('totalshares','getTotalShares');
Also, the total share counts are shown right below the post title, so maybe that prevents the page from rendering? I’ve added the shortcode in loop-sigle.php right below the page title and above the category and date meta.
Without this function the website will load very quickley, even without cache, due to the nginx set up.
-
This reply was modified 12 years by
r1kay.
My personal thinking is that if sharedcount is going out and grabbing the data for you, and then you’re grabbing data from them, it seems to be an obvious slowdown.
Since you’re using the (apparently) ‘free/unauthenticated API’ you not only have to contend with the 10,000 queries limit, but are also in the pool with all other free users, and obviously this is a slowdown someplace, perhaps it’s fetching the graphic before service code which would introduce delay for it to fetch that and serve back to you; dunno.
You might pay for one month trial on their upgraded “PLUS” plan to get the better connection?
I’d likely do a split test among services
1) theme built-in features
2) what you’re using now
3) AddThis Sharing (or ShareThis if you prefer)
Run speed tests with GTMetrix or something and measure the speed FROM THAT API compared to speed of other methods, and go with what is faster.
Marius/Radu may have better answer. 🙂
-
This reply was modified 12 years by
simchris.
Well i’ve tested a clean php code (without image) that they provide for php in a single script with and without api key and it returns the correct count immediately. Then i’ve tested that clean code within functions.php (and added the created shortcode in the post template) and it delays. Then i’ve tested the clean php code by adding it directly to loop-single.php (without shortcode) and it also delays. So i think it doesnt have anything to do with the sharedcount api or response time, but with the page rendering. For example, category pages that dont contain this code are loaded instantly. Somehow the post pages rendering slows down.
All tests were done without caching to measure respone time.
Hey Christopher! When I run the script (with api key) locall with wamp server, the response time is almost zero. When executing the code on my server (by putting a clean php code in the root and execute it by requesting the file), there’s a delay. Almost 7 seconds delay. Now, i know you are also running a plesk server, do you know if it could have to do something with my server settings? I already tested it by processing PHP by Apache instead of nginx but that doesn’t make a difference. I’m on PHP version 5.4.23, but maybe i’m missing some php extensions?
-
This reply was modified 12 years by
r1kay.
Wow. 7 seconds is a lifetime ! It might be due to running a proxy? A lot of folks running nginx (we’re running Apache, and then nginx for SOME things not all) seem to run through a proxy, and that might cause the issue. Perhaps check amount of memory allocated to PHP ? I think mine is set to 512MB, with 256M being typically the best lower limit for WP these days. I think you already checked that.
If you can see a noticeable slowdown running that just from the server, two things you might try is a traceroute between the API IP and your DNS, and/or check with your hosting provider to explain the issue. It might be something they have run across before.
Or it could be some weirdo voodoo thing like why my stupid Font Awesome 4 CSS don’t load consistently off Amazon’s CDN, or from the free CDN that also hosts bootstrap. Gave up on that one 🙂