2

How do I measure site speed for logged in users? The tools like pingdom, google page speed etc, check site speed for guests. the reason I ask is this.

My site is fast for guests because I have page caching. For logged in users, I don't have the pages cached and hence it is extremely slow. The end result is that my most loyal visitors (logged in users) are getting a slow site. If I can accurate measure it, I can move towards fixing it. Appreciate the help.

MultiDim
  • 21
  • 1

1 Answers1

1

I handled this by creating a test user on the system (let's call the login my_test_user) and then added an action hook on init to check the URL for a token, and if the token is found it logs in as the test user before running the rest of the page. You can use whatever you want as the token as long as it is long and random enough, but this is a decent generator. Keep in mind that you should be using this via SSL (but then again, so should your logins with password).

From a security standpoint I would recommend hard coding the test user either in the code or as a constant in wp-config.php. If this is ever compromised, you don't want the hacker to be able to log in as any user, and your test user should have limited permissions. Perhaps even consider another token/key to enable/disable the functionality based on a wp_option value and only turn on when testing.

Once added to your functions.php you can use any URL in your tools appended with ?login_token=YOUR_LOGIN_TOKEN to view it as my_test_user.

function auto_login() {
    $login_token = isset( $_GET['login_token'] )? $_GET['login_token'] : false;
    // get a UUID from http://www.uuidgenerator.net/
    if ( $login_token == 'ac88dc0e-72a8-4a22-abc0-fb5b5396c0ac' ){
        // The test user we want to log in
        $user_login = 'my_test_user';
        // Get the user info
        $user = get_user_by( 'login', $user_login );

        // Log the test user in automatically
        wp_set_current_user( $user->ID, $user_login );
        wp_set_auth_cookie( $user->ID );
        do_action( 'wp_login', $user_login );
    }
}
// Set with a priority of 1 so that it runs ASAP
add_action( 'init', 'auto_login', 1 );
doublesharp
  • 26,888
  • 6
  • 52
  • 73
  • Ah cool! Thanks doublesharp. Couple of follow-ups. 1) where do I put this code. 2) doesn't the tool now add also the time it takes to login, instead of just the pagespeed alone? – MultiDim Aug 25 '14 at 21:26
  • Put this into your `functions.php`. There isn't any more load than with a "logged in" user. In a real-world case a login cookie is set which is sent with every request, we are just moving it to the querystring. Wordpress normally does the lookup/login based on the cookie, we are doing it slightly differently to expose it to the URL. – doublesharp Aug 25 '14 at 21:28
  • one suggestion people was saying is to use yahoo yslow add-on for firebug in firefox. Since it is a plugin and if I do yslow when I am logged in, it gives site speed for logged in users. Is that true? Thanks for your help. – MultiDim Aug 27 '14 at 22:16
  • That would work, but it also means that your system is in the mix so you have to factor in plugins, apps that are open, things that are installed, etc, plus *you* have to do the testing (no automation). – doublesharp Sep 02 '14 at 17:11
  • @doublesharp, doesn't this add extra overhead to the benchmark? What is your esteem on this? – Riccardo Sep 30 '19 at 08:33
  • @Riccardo it does add overhead, as anything "new" you add to a project would, but it is pretty minimal in the big scheme of things, and definitely good enough to troubleshoot performance – doublesharp Sep 30 '19 at 14:48
  • Works perfectly! – Riccardo Sep 30 '19 at 17:20