Skip to content

Instantly share code, notes, and snippets.

View mesaque's full-sized avatar

Mesaque Silva mesaque

View GitHub Profile
#see amount of memory a soft will use:
ps --no-headers -o "rss,cmd" -C php-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
ps --no-headers -o "rss,cmd" -C php-fpm | grep elitte_ps | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'
@mesaque
mesaque / lib.sh
Last active June 30, 2016 12:35
shell utils
_abbreev_num(){
case ${#1} in
1|2|3|4) _ABBREV_NUM=${1}B
;;
5|6) _ABBREV_NUM=$(( ($1 + 500)/ 1000 ))K
;;
7|8|9) _ABBREV_NUM=$(( ($1 + 500000) / 1000000 ))M
;;
10|11|12) _ABBREV_NUM=$(( ($1 + 500000000) / 1000000000 ))G
;;
set_error_handler("myErrorHandler");
function myErrorHandler($errno, $errstr, $errfile, $errline){
switch ($errno) {
case E_USER_ERROR:
file_put_contents('/tmp/debug.log', "[Fatal error]{$errstr} \n", FILE_APPEND);
break;
case E_USER_WARNING:
file_put_contents('/tmp/debug.log', "[WARNING]{$errstr} \n", FILE_APPEND);
break;
#Know your need for Recommended InnoDB Buffer Pool Size
# innodb_buffer_pool_size
# https://tools.percona.com/dashboard
SELECT CONCAT(CEILING(RIBPS/POWER(1024,pw)),SUBSTR(' KMGT',pw+1,1))
Recommended_InnoDB_Buffer_Pool_Size FROM
(
SELECT RIBPS,FLOOR(LOG(RIBPS)/LOG(1024)) pw
FROM
(
SELECT SUM(data_length+index_length)*1.1*growth RIBPS
git for-each-ref --format='%(committerdate:iso8601) %(committerdate:relative) %(refname)' --sort -committerdate
add_filter( 'query', 'hot_cold_database_logic' );
function hot_cold_database_logic( $query ){
global $wpdb, $pagenow;
if ( strpos( $query, sprintf( '%sposts' , $wpdb->prefix ) ) === false ) return $query;
if ( strpos( $query, 'SQL_CALC_FOUND_ROWS' ) !== false ) return $query;
if ( in_array( $pagenow, array( 'post.php', 'post-new.php' ) ) ) return $query;
$query_posts = $query;
$limiters_orders = '';
select count(meta_key) as cnt_key, left(meta_key, 21) as prefix from wp_cRRbrl_postmeta group by prefix limit 10;
#First you need to active profiling on your mysql
set profiling = 1;
#run some queries and see the status
show profiles;
#after that you cant set the variable and see the query full details
SET @query_id = 1;
SELECT STATE, SUM(DURATION) AS Total_R,