• Hey guys, Im currently running a gaming news website thats getting roughly 130-250 Visitors a day (Only half that according to Google Analytic’s).

    My host is Godaddy at the highest possible Level for memory usage which is 2048mb. whenever i post a page link on twitter/facebook my site gets alot of 500 Internal Server Errors and also sometimes 503 Service unavailable, But im only getting max 20-40 visitors from the link.

    I had just obtained 17 visitors from a twitter post all at once and my Hosting panel says –

    CPU Usage
    80 / 100 %
    Memory Usage
    2,046.1 / 2048 MB

    Is this normal for such a small traffic website? if not how can i lower the huge memory usages? any help is appreciated! thanks

Viewing 13 replies - 1 through 13 (of 13 total)
  • Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    No, that doesn’t much sense for a site that size. In fact, you should need more than 128 MB for a site that size/active. Something else must be the cause of the problem.

    Internal server errors (error 500) are often caused by plugin or theme function conflicts, so if you have access to your admin panel, try deactivating all plugins. If you don’t have access to your admin panel, try manually resetting your plugins (no Dashboard access required). If that resolves the issue, reactivate each one individually until you find the cause.

    If that does not resolve the issue, try switching to the Twenty Fourteen theme to rule-out a theme-specific issue. If you don’t have access to your admin panel, access your server via FTP or SFTP, navigate to /wp-content/themes/ and rename the directory of your currently active theme. This will force the default theme to activate and hopefully rule-out a theme-specific issue.

    If that does not resolve the issue, it’s possible that a .htaccess rule could be the source of the problem. To check for this, access your server via FTP or SFTP and rename the .htaccess file. If you can’t find a .htaccess file, make sure that you have set your FTP or SFTP client to view invisible files.

    If you weren’t able to resolve the issue by either resetting your plugins and theme or renaming your .htaccess file, we may be able to help, but we’ll need a more detailed error message. Internal server errors are usually described in more detail in the server error log. If you have access to your server error log, generate the error again, note the date and time, then immediately check your server error log for any errors that occurred during that time period. If you don’t have access to your server error log, ask your hosting provider to look for you.

    Thread Starter pahroblem

    (@pahroblem)

    Hey mate thanks for your detailed reply!

    The memory spike only happens when we link a post from our website on twitter or facebook and get hit with traffic (30 visitors max) and goes away within 5-10min. So how would i go about testing out the plugins one at a time?

    The only error ive ever had is

    [01-Jul-2015 16:16:50 UTC] WordPress database error Lost connection to MySQL server during query for query SELECT option_value FROM wp_options WHERE option_name = 'bwp_gxs_google_news' LIMIT 1 made by require('wp-blog-header.php'), require_once('wp-load.php'), require_once('wp-config.php'), require_once('wp-settings.php'), include_once('/plugins/bwp-google-xml-sitemaps/bwp-simple-gxs.php'), BWP_SIMPLE_GXS->__construct, BWP_FRAMEWORK_IMPROVED->build_properties, BWP_FRAMEWORK_IMPROVED->pre_init_actions, BWP_FRAMEWORK_IMPROVED->pre_init_build_options, BWP_FRAMEWORK_IMPROVED->build_options, get_option, W3_Db->query, W3_DbCache->query, W3_DbCallUnderlying->query, W3_Db->query, W3_DbProcessor->query, W3_Db->default_query

    which i had yesterday when the last error happened. i had just deactivated that plugin and 2minutes later i got a 500 internal server error but theres nothing else in the error log. :/

    I’ve tried several things ive googled such as renaming plugin folder, renaming htaccess and also renaming the theme name and i still get these errors!

    Thread Starter pahroblem

    (@pahroblem)

    Sorry for the double posts but i cannot edit older ones, ive been at this for hours… my page is now taking 10-15seconds to load. 80% of the time it turns into a [profanity] error.

    I installed a plugin called P3 which scans page loading times and shows you what plugins are taking up time. I had a plugin called Contact forms that took 49% of the time out of 32 plugins, tried to deactivate/delete it and got a error so i deleted it manually now my page isnt loading whatsoever… is there anyone that can help here im desperate.

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Sounds like your BWP plugin may actually be the problem.

    As for the lockout, try manually resetting your plugins (no Dashboard access required). If that resolves the issue, reactivate each one individually until you find the cause.

    Thread Starter pahroblem

    (@pahroblem)

    Big edit:

    Ok so after lots of stuffing around ive finally found the problem, well the location atleast. I renamed my Functions file and it fixed the loading times, the file was producing 1200~ MySQL queries per visit! I dont know why its suddenly changed as i havent edited it in over a month.

    About to try narrow it down to which part but i cant understand how they could make such a big difference, its all little snippets to change minor things such as user URL to user ID and stuff like that…

    If anyone can help find out how i can fix it without having to delete functions that would be great, here is my Functions file in my child theme.

    <?php
    
    //* User Submitted Custom Post Type -------------------------------------------------------------------------------------------------
    
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
      register_post_type( 'user-posts',
        array(
          'labels' => array(
            'name' => __( 'user posts' ),
            'singular_name' => __( 'user post' )
          ),
          'public' => true,
          'has_archive' => true,
        )
      );
    }
    
    //* Multiple Thumbnails -------------------------------------------------------------------------------------------------
    if (class_exists('MultiPostThumbnails')) {
        new MultiPostThumbnails(
            array(
                'label' => 'Post Image',
                'id' => 'post-image',
                'post_type' => 'post'
            )
        );
    }
    
    //* Excerpt for post items -------------------------------------------------------------------------------------------------
    function get_excerpt($count){
      $permalink = get_permalink($post->ID);
      $excerpt = get_the_content();
      $excerpt = strip_tags($excerpt);
      $excerpt = substr($excerpt, 0, $count);
      $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
      $excerpt = $excerpt.' <a href="'.$permalink.'"></a>';
      return $excerpt;
    }
    
    //* Remove the link 'SEO' from admin bar. It's placed there by the plugin WordPress SEO by Yoast. ---------------------------------------------------------
    function remove_admin_bar_links() {
    	global $wp_admin_bar;
    	$wp_admin_bar->remove_menu('comments');
    	$wp_admin_bar->remove_menu('wpseo-menu');
    }
    add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
    
    // Our custom post type function -------------------------------------------------------------------------------------------------
    function create_posttype() {
    
    	register_post_type( 'Reviews',
    	// CPT Options
    		array(
    			'labels' => array(
    				'name' => __( 'reviews' ),
    				'singular_name' => __( 'review' )
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'reviews'),
                            'supports' => array( 'title', 'editor', 'comments', 'excerpt', 'custom-fields', 'thumbnail' ),
                            'taxonomies' => array( 'post_tag', 'platform' )
    		)
    	);
    }
    // Hooking up our function to theme setup
    add_action( 'init', 'create_posttype' );
    
    //Set up Custom Meta Boxes-----------------------------------
    function add_my_metaboxes() {
    	add_meta_box('my_metabox', 'Review Overview', 'my_metabox', 'reviews', 'side', 'high');
    }
    
    add_action( 'add_meta_boxes', 'add_my_metaboxes', 10, 2);
    
    //Display My Meta Box
    function my_metabox() {
    	global $post;
    	//Noncename needed to verify where the data originated
    	wp_nonce_field( 'save_my_metabox', '_wpnonce-mymetabox' );
    
    	//Get the stats data if its already been entered
    
    	$Score = get_post_meta($post->ID, 'mymetabox_Score', true);
    
    	$Developer = get_post_meta($post->ID, 'mymetabox_Developer', true);
    
    	$Genre = get_post_meta($post->ID, 'mymetabox_Genre', true);
    
            $Pro1 = get_post_meta($post->ID, 'mymetabox_Pro1', true);
    
            $Pro2 = get_post_meta($post->ID, 'mymetabox_Pro2', true);
    
            $Pro3 = get_post_meta($post->ID, 'mymetabox_Pro3', true);
    
            $Con1 = get_post_meta($post->ID, 'mymetabox_Con1', true);
    
            $Con2 = get_post_meta($post->ID, 'mymetabox_Con2', true);
    
    	//Echo out the fields
    
            echo "<label for='Score'>Score:</label><input id='Score' type='text' name='mymetabox_Score' value='" . $Score  . "' class='widefat' />";
    
    	echo "<label for='Developer'>Developer:</label><input id='Developer' type='text' name='mymetabox_Developer' value='" . $Developer  . "' class='widefat' />";
    
    	echo "<label for='Genre'>Genre:</label><select id='Genre' name='mymetabox_Genre' value='" . $Genre  . "' class='widefat' />
            <option value='unselected' " . selected($Genre,'unselected',false) . ">--Select Option--</option>
            <option value='RPG' " . selected($Genre,'RPG',false) . ">RPG</option>
            <option value='SHOOTER' " . selected($Genre,'SHOOTER',false) . ">SHOOTER</option>
            <option value='ACTION' " . selected($Genre,'ACTION',false) . ">ACTION</option>
            <option value='MOBA' " . selected($Genre,'MOBA',false) . ">MOBA</option>
            <option value='STRATEGY' " . selected($Genre,'STRATEGY',false) . ">STRATEGY</option></select>";
    
            echo "<label for='Pro1'>Pro 1:</label><input id='Pro1' type='text' name='mymetabox_Pro1' value='" . $Pro1  . "' class='widefat' />";
    
            echo "<label for='Pro2'>Pro 2:</label><input id='Pro2' type='text' name='mymetabox_Pro2' value='" . $Pro2  . "' class='widefat' />";
    
            echo "<label for='Pro3'>Pro 3:</label><input id='Pro3' type='text' name='mymetabox_Pro3' value='" . $Pro3  . "' class='widefat' />";
    
            echo "<label for='Con1'>Con 1:</label><input id='Con1' type='text' name='mymetabox_Con1' value='" . $Con1  . "' class='widefat' />";
    
            echo "<label for='Con2'>Con 2:</label><input id='Con2' type='text' name='mymetabox_Con2' value='" . $Con2  . "' class='widefat' />";
    
    }
    
    //Save the My Metabox Data
    function save_my_metabox_meta($post_id, $post) {
    	//Verify nonce
    	if ( !wp_verify_nonce( $_POST['_wpnonce-mymetabox'], 'save_my_metabox' )) {
    		return $post->ID;
    	}
    	//Verify permission
    	if ( !current_user_can( 'edit_post', $post->ID ))
    		return $post->ID;
    	//Store values in an array
    
    	$mymetabox_data['mymetabox_Score'] = $_POST['mymetabox_Score'];
    	$mymetabox_data['mymetabox_Developer'] = $_POST['mymetabox_Developer'];
    	$mymetabox_data['mymetabox_Pro1'] = $_POST['mymetabox_Pro1'];
    	$mymetabox_data['mymetabox_Pro2'] = $_POST['mymetabox_Pro2'];
    	$mymetabox_data['mymetabox_Pro3'] = $_POST['mymetabox_Pro3'];
    	$mymetabox_data['mymetabox_Con1'] = $_POST['mymetabox_Con1'];
    	$mymetabox_data['mymetabox_Con2'] = $_POST['mymetabox_Con2'];
    	$mymetabox_data['mymetabox_Genre'] = $_POST['mymetabox_Genre'];
    
    	// Store values of $mymetabox_data as custom fields
    	foreach ($mymetabox_data as $key => $value) {
    		if( $post->post_type == 'revision' ) return; // Don't store custom data twice
    		$value = implode(',', (array)$value); // If $value is an array, make it a CSV (unlikely)
    		if(get_post_meta($post->ID, $key, FALSE)) { // If the custom field already has a value, update it
    			update_post_meta($post->ID, $key, $value);
    		} else { // If the custom field doesn't have a value, create it
    			add_post_meta($post->ID, $key, $value);
    		}
    		if(!$value) delete_post_meta($post->ID, $key); // Delete if blank
    	}
    }
    
    add_action('save_post', 'save_my_metabox_meta', 1, 2); // save the custom field
    
    // Custom taxonomies for platform -------------------------------------------------------------------------------------------------
    /**
     * Add custom taxonomies
     *
     * Additional custom taxonomies can be defined here
     * http://codex.wordpress.org/Function_Reference/register_taxonomy
     */
    
    function add_custom_taxonomies() {
      // Add new "Platform" taxonomy to Posts
      register_taxonomy('platform', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
          'name' => _x( 'Platforms', 'taxonomy general name' ),
          'singular_name' => _x( 'Platform', 'taxonomy singular name' ),
          'search_items' =>  __( 'Search Platforms' ),
          'all_items' => __( 'All Platforms' ),
          'parent_item' => __( 'Parent platform' ),
          'parent_item_colon' => __( 'Parent platform:' ),
          'edit_item' => __( 'Edit platform' ),
          'update_item' => __( 'Update platform' ),
          'add_new_item' => __( 'Add New platform' ),
          'new_item_name' => __( 'New platform Name' ),
          'menu_name' => __( 'Platforms' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
          'slug' => 'platforms', // This controls the base slug that will display before each term
          'with_front' => false, // Don't display the category base before "/locations/"
          'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
      ));
    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    
    // Change my account to say welcome -------------------------------------------------------------------------------------------------
    add_action( 'admin_bar_menu', 'wp_admin_bar_my_custom_account_menu', 11 );
    
    function wp_admin_bar_my_custom_account_menu( $wp_admin_bar ) {
        $user_id = get_current_user_id();
        $current_user = wp_get_current_user();
        $profile_url = get_edit_profile_url( $user_id );
    
    if ( 0 != $user_id ) {
        /* Add the "My Account" menu */
        $avatar = get_avatar( $user_id, 28 );
        $howdy = sprintf( __('Welcome, %1$s'), $current_user->display_name );
        $class = empty( $avatar ) ? '' : 'with-avatar';
    
        $wp_admin_bar->add_menu( array(
            'id' => 'my-account',
            'parent' => 'top-secondary',
            'title' => $howdy . $avatar,
            'href' => $profile_url,
            'meta' => array(
            'class' => $class,
        ),
    ) );
    
    }
    }
    
    // review star score -------------------------------------------------------------------------------------------------
    
    function gamergreed_score() {
      //set variables
      $starheight = 64;
      $background_offset = get_post_meta( get_the_ID(), 'mymetabox_Score', true ) * $starheight;
      //echo out a div with the background position value based on the above variables
      echo '<div class="review-score" style="background-position: center -' . $background_offset . 'px;"></div>';
    }
    
    // change footer name in dashboard -------------------------------------------------------------------------------------------------
    
    function remove_footer_admin () {
        echo "Always remember that you're awesome!";
    }
    
    add_filter('admin_footer_text', 'remove_footer_admin');
    
    // Removes the wp-logo on dashboard -------------------------------------------------------------------------------------------------
    
    function wps_admin_bar() {
        global $wp_admin_bar;
        $wp_admin_bar->remove_node('wp-logo');
    }
    add_action( 'wp_before_admin_bar_render', 'wps_admin_bar' );
    
    //function to shorten freshness display from say '1 month, 2 weeks' to '1 month'----------------------------------------------
    
    function short_freshness_time( $output) {
    $output = preg_replace( '/, .*[^ago]/', ' ', $output );
    return $output;
    }
    add_filter( 'bbp_get_time_since', 'short_freshness_time' );
    add_filter('bp_core_time_since', 'short_freshness_time');
    
    // Change username url to display -------------------------------------------------------------------------------------------------
    
    add_action( 'init', 'nicenames_to_display_name' );
    function nicenames_to_display_name() {
        foreach ( get_users() as $user ) {
    		if ( $user->data->user_status == 0 && $user->data->user_nicename != $user->data->display_name ) {
    			$user_ids[] = $user->ID;
    		}
    	}
    	foreach( $user_ids as $uid ) {
    		$info = get_userdata( $uid );
    		$display_name = $info->data->display_name;
    		if ($display_name) {
    			$args = array(
    				'ID'            => $uid,
    				'user_nicename' => strtolower(str_replace(" ", "_", $display_name))
    			);
    			wp_update_user( $args );
    		}
    	}
    }
    
    // Filter wp_nav_menu() to add profile link ----------------------------------------------------------------------------------------------
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
    function my_nav_menu_profile_link($menu) {
        if (!is_user_logged_in())
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_id ;
            $profilelink = '<li><a href="/forum/users/' . $user . '">Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
    
    }
    
    // Forum topic title length -------------------------------------------------------------------------------------------------
    
    add_filter ('bbp_get_title_max_length','change_title') ;
    
    Function change_title ($default) {
    $default=54 ;
    Return $default ;
    }
    
    // Disable admin bar -------------------------------------------------------------------------------------------------
    
    add_action('after_setup_theme', 'remove_admin_bar');
    
    function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
    }
    
    //  replaces forum role names -------------------------------------------------------------------------------
    
    add_filter( 'bbp_get_dynamic_roles', 'ntwb_bbpress_custom_role_names' );
    
    function ntwb_bbpress_custom_role_names() {
    	return array(
    
    		// Keymaster
    		bbp_get_keymaster_role() => array(
    			'name'         => 'Admin',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_keymaster_role() )
    		),
    
    		// Moderator
    		bbp_get_moderator_role() => array(
    			'name'         => 'Moderator',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_moderator_role() )
    		),
    
    		// Participant
    		bbp_get_participant_role() => array(
    			'name'         => 'Member',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_participant_role() )
    		),
    
    		// Spectator
    		bbp_get_spectator_role() => array(
    			'name'         => 'Guest',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_spectator_role() )
    		),
    
    		// Blocked
    		bbp_get_blocked_role() => array(
    			'name'         => 'Blocked',
    			'capabilities' => bbp_get_caps_for_role( bbp_get_blocked_role() )
    		)
    	);
    }
    
    //  replaces forum author first/last name to username-------------------------------------------------------------------------------
    
    function replace_bbpress_replies_username_filter($author_name,$reply_id ){
    $author_id = bbp_get_reply_author_id($reply_id);
    $author_object = get_userdata( $author_id );
    $author_name  = ucfirst($author_object->user_login);
    return $author_name;
    }
    add_filter( 'bbp_get_reply_author_display_name','replace_bbpress_replies_username_filter',10, 2);
    
    //  replaces profile url to user ID eg admin = #1 ------------------------------------------------------------------------------
    
    remove_filter( 'bbp_get_user_profile_url', 'bbp_get_user_profile_url');
    add_filter('bbp_get_user_profile_url','my_replaced' , 10 ,4);
    function my_replaced ($url, $user_id, $user_nicename = '' ){
    	global $wp_rewrite;
    	if ( empty( $user_id ) ) {return false;}
    	$early_profile_url = apply_filters( 'bbp_pre_get_user_profile_url', (int) $user_id );
    	if ( is_string( $early_profile_url ) ) {   return $early_profile_url; }
    	if ( $wp_rewrite->using_permalinks() ) { 	// if pretty permalinks
    		$url = $wp_rewrite->root . bbp_get_user_slug() . '/%' . bbp_get_user_rewrite_id() . '%';
    		if ( empty( $user_nicename ) ) { $user_nicename = bbp_get_user_nicename( $user_id );}
    
    		$url = str_replace( '%' . bbp_get_user_rewrite_id() . '%', $user_id, $url );
    		$url = home_url( user_trailingslashit( $url ) );
    
    	}
    	else { 	// Unpretty permalinks
    		$url = add_query_arg( array( bbp_get_user_rewrite_id() => $user_id ), home_url( '/' ) );
    	}
    	//return apply_filters( 'Replaced_bbp_get_user_profile_url', $url, $user_id, $user_nicename );
    	return $url;
    }	
    
    ?>
    Thread Starter pahroblem

    (@pahroblem)

    hour later still trying to work this out….

    Edit: everything now seems to be ok, loading time fixed and no more errors(yet!)

    The only problem im currently having is my Memory usage is bouncing up and down from 200-900mb. what could be causing this? :/

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    If you rename the functions.php file again, does the memory usage nightmare stop?

    If so, I recommend just removing each action/filter section one-by-one until the problem goes away. Once it does, you’ve found the source of all your troubles.

    Thread Starter pahroblem

    (@pahroblem)

    I fixed that issue, somehow bbpress snippets were doing it. didnt have much need for bbpress so removed it completely and the snippets. Funtion.php is working fine now. Memory usage is currently at 160mb with only 6 visitors isnt that a bit too high? i havent ran into any errors yet so thats a plus. this memory usage problem is why i keep getting them though because the resource limit is constantly being reached

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    It’s a bit high, you should be somewhere between 32 MB and 128 MB depending on what plugins you’re using.

    Don’t rely on P3 at this point. Try deactivating *all* plugins. If that resolves the issue, reactivate each one individually until you find the cause.

    If that does not resolve the issue, try switching to the Twenty Fifteen theme to rule-out a theme-specific issue (theme functions can interfere like plugins).

    Thread Starter pahroblem

    (@pahroblem)

    Alright so i was on 180mb going up and down.

    Deactivated all plugins and changed theme, refreshed Cpanel page a few times.
    Memory Usage 270mb going up and down.

    edit: refreshed again 589mb.

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    1. Is that with absolutely *no* plugins active and the Twenty Fifteen theme enabled with *no* child theme?

    2. Are you running any other PHP apps on your server?

    3. What are you using to track the memory usage?

    Thread Starter pahroblem

    (@pahroblem)

    yeah no plugins and twenty fifteen theme.

    I dont think so? wouldnt know that they are man lol

    My Linux Cpanel. shows me all the stats cpu, memory, processes etc

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    Ok, you might have to ask your hosting provider to take a closer look. There’s absolutely no way WordPress would need 589 MB with no plugins and the Twenty Fifteen theme. I have seen it operate perfectly under 32 MB.

    Either something is misconfigured with the server, or you have some nasty malware hiding in there.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Memory Usage’ is closed to new replies.