php - How to make optimize ajax or request from cache -


i have server amazon cloud , have around 20k visitor @ time, problem is, introduced section site , load content depend upon height of page.

e.g. if page have 2000px height , request around 40 post's , ok small number of visitor not more 1000 visitor (at particular time).

its halt server , crashed mysql when activate , there way can smoothly post without loosing visitor ?

then request post in 5-5 group using

function sfpside_bar_post_request(sfpnumber_of_post) {         icounti = 1;         numbverofrequest = math.floor(sfpnumber_of_post / 3);         remainderpost = sfpnumber_of_post % 3;         spi = setinterval(function() {             if (icounti > numbverofrequest)             {                 handle_sidepost(remainderpost,icounti);                 clearinterval(spi);             }else{               handle_sidepost(3,icounti);               }             icounti++;         }, 1000);     }     function handle_sidepost(num_post,count) {         var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';         var data = {             wp_nonce: '<?php echo wp_create_nonce('sfp_forum_secret_no_one_knows_latest_sidebar'); ?>',             action: 'sfp_sidebar_random_sidebar',             post_num: num_post,         };          jquery.ajax({             'async': true,             'type': 'post',             'url': ajaxurl,             'data': data,             'success': function(data)             {                 var sidepost = jquery.parsejson(data);                 sidepostcontent = '<div id="sidesfppost'+count+'">';                 (icount = 0; icount < sidepost.length; icount++) {                     sidepostcontent += '<div class="sidebar-one-half"><div class="post_img">';                     sidepostcontent += sidepost[icount].image;                     sidepostcontent += '</div><article><div class="sflike">';                     sidepostcontent += sidepost[icount].like;                     sidepostcontent += '</div><div class="conten_wrap left"><h2>';                     sidepostcontent += sidepost[icount].title;                     sidepostcontent += '</h2></div></article><div class="snippet-box"><div class="left"><p class="sfp_greybtn">';                     sidepostcontent += sidepost[icount].greybutton;                     sidepostcontent += '</p></div><div class="right">';                     sidepostcontent += sidepost[icount].circle;                     sidepostcontent += '</div></div></div>';                 }                 sidepostcontent += "</div>";                 jquery("#sfppost_sidebar_extra_post").append(sidepostcontent);                 jquery(function() {                     jquery("#sidesfppost"+count+" img.imgload").css("width", "54px");                     jquery("#sidesfppost"+count+" img.imgload").css("height", "55px");                     jquery("#sidesfppost"+count+" img.imgload").lazyload({                         load: image_loaded_page,                         effect: "fadein",                         failure_limit: 10,                         threshold: 200                     });                 });             },             contenttype: "application/x-www-form-urlencoded;charset=iso-8859-15"         });     } 

but still crashes mine mysql

the wp used request post

if ($_post['action'] == 'sfp_sidebar_random_sidebar' && wp_verify_nonce($_post['wp_nonce'], 'sfp_forum_secret_no_one_knows_latest_sidebar')):          $args = array('posts_per_page' => $_post['post_num'], 'orderby' => 'rand', 'post_type' => 'sfp_forum');         $rand_posts = get_posts($args);         $icount = 0;         $postdata = array();         foreach ($rand_posts $post_data) :             setup_postdata($post_data);             $postdata[$icount]['image'] = get_post_home_picture($post_data->post_content, $post_data->id, $post_data->post_title, $author_username, 'category-small-thumb', 275, 416, true, true);             $postdata[$icount]['like'] = sfp_like_disklike_arrows("poplr", $post_data->id, true);             $postdata[$icount]['title'] = "<a href='" . get_permalink($post_data->id) . "'>" . sfp_strip_content($post_data->post_title, 50) . "</a>";             $postdata[$icount]['greybutton'] = sfp_get_grey_button($post_data->id, $post_data->post_title, true);             $postdata[$icount]['circle'] = sfp_home_postcircle($post_data->id, $post_data->comment_count, true);             $icount++;         endforeach;         wp_reset_postdata();         echo json_encode($postdata);     endif;     die; 

i have little thought optimize ajax request,

here code:--

var oldsearchdata = new array(); function handle_sidepost(num_post,count) {     var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';     var data = {             wp_nonce: '<?php echo wp_create_nonce('sfp_forum_secret_no_one_knows_latest_sidebar'); ?>',             action: 'sfp_sidebar_random_sidebar',             post_num: num_post,         };     if(oldsearchdata[num_post])     {         data = oldsearchdata[num_post];     } else {         jquery.ajax({             'async': true,             'type': 'post',             'url': ajaxurl,             'data': data,             'success': function(data)             {                 oldsearchdata[num_post] = data;                 //do action.             }         });     } } 

you can save state in ajax array...

hope little....

another solution :- use wp super cache plugin...


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -