WordPress.org

Ready to get started?Download WordPress

Forums

Top 10 - Popular posts plugin for WordPress
[Plugin: Top 10] (Idea) Speed up top 10 ajax request (13 posts)

  1. uradvd
    Member
    Posted 1 year ago #

    <?php
    //"top-10-counter.js.php" Display number of page views
    Header("content-type: application/x-javascript");
    
    <strong>define('SHORTINIT', 'faster');</strong>
    
    if (!function_exists('add_action')) {
    	$wp_root = '../../..';
    	if (file_exists($wp_root.'/wp-load.php')) {
    		require_once($wp_root.'/wp-load.php');
    	} else {
    		require_once($wp_root.'/wp-config.php');
    	}
    }

    good idea?

    http://wordpress.org/extend/plugins/top-10/

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

  2. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Am not sure if the code got properly displayed.

    The change I see is define('SHORTINIT', 'faster');

    Am not sure how this helps?

    I believe define('SHORTINIT', true); loads a lighter environment, but I can run some tests to see if it helps speed up the page.

  3. uradvd
    Member
    Posted 1 year ago #

    sorry, yes

    define( 'SHORTINIT', TRUE );

    minimun load environment. Not load /wp-includes, /wp-content
    only $wpdb
    Low memory usage(not load full wordpress environment), speed up ajax request

  4. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    I just tried it in my test blog and its given a decent performance improvement. I'll implement this in the next version.

  5. uradvd
    Member
    Posted 1 year ago #

    great thanks!!!!!

  6. uradvd
    Member
    Posted 1 year ago #

    WARNING: [pool www] child 96782, script '/data/site/wp-content/plugins/top-10/top-10-counter.js.php' (request: "GET /wp-content/plugins/top-10/top-10-counter.js.php") executing too slow (1.785353 sec), logging

    4k users
    30k pageviews/day

  7. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    Is this the default option?

    Did the code above work for you if you edit top-10-counter.js.php ?
    It gives a 500 error in my testing.

    It did work on the top-10-addcount.js.php

  8. uradvd
    Member
    Posted 1 year ago #

    yes is defaul plugin options

    most likely because there is a code which is present in the part which we disable

  9. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    I thought as much. Let me see what I can do. But, just disabling the addcount which is the main one, saves a good amount of time.

  10. uradvd
    Member
    Posted 1 year ago #

    speedup 500%
    I think to create a separate function for each counter as this increases the performance counter display

    <?php
    //"top-10-counter.js.php" Display number of page views
    Header("content-type: application/x-javascript");
    define( 'SHORTINIT', TRUE );
    if (!function_exists('add_action')) {
    	$wp_root = '../../..';
    	if (file_exists($wp_root.'/wp-load.php')) {
    		require_once($wp_root.'/wp-load.php');
    	} else {
    		require_once($wp_root.'/wp-config.php');
    	}
    }
    // Display counter using Ajax
    function tptn_disp_count_total() {
    	global $wpdb;
    
    	$table_name = $wpdb->prefix . "top_ten";
    	$count_disp_form = "Views %totalcount%";
    
    	$id = intval($_GET['top_ten_id']);
    	if($id > 0) {
    
    		// Total count per post
    		if (strpos($count_disp_form, "%totalcount%") !== false) {
    			$resultscount = $wpdb->get_row("SELECT postnumber, cntaccess FROM ".$table_name." WHERE postnumber = ".$id);
    			$cntaccess = number_format((($resultscount) ? $resultscount->cntaccess : 1));
    			$count_disp_form = str_replace("%totalcount%", $cntaccess, $count_disp_form);
    		}
    echo 'document.write("'.$count_disp_form.'")';
  11. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    uradvd, I think this is because the above function isn't fetching the tptn_settings

    $tptn_settings = tptn_read_options();

    I think this read function makes all the difference, and not because of the %totalcount% option only.

  12. uradvd
    Member
    Posted 1 year ago #

    If you refer to the settings plug if we lose in performance, I think it is better to select the individual components and winning performance

  13. Ajay
    Member
    Plugin Author

    Posted 1 year ago #

    I agree. I think I should be able to modify the code to gain performance.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.