Skip to content

Instantly share code, notes, and snippets.

View mesaque's full-sized avatar

Mesaque Silva mesaque

View GitHub Profile
#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,
select count(meta_key) as cnt_key, left(meta_key, 21) as prefix from wp_cRRbrl_postmeta group by prefix limit 10;
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 = '';
git for-each-ref --format='%(committerdate:iso8601) %(committerdate:relative) %(refname)' --sort -committerdate
#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
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;
@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
;;
#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 / php5-fpm
Created March 8, 2016 12:20
PHP_FPM init.d
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-5.6.0-fpm
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-5.6.0-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
{
"domain":"http:\/\/www.correiodeuberlandia.apikihost.com",
"product":1,
"message":{
"post":{
"post_date":"2016-04-27 20:32:53",
"post_excerpt":"",
"post_type":"errors_log",
"post_status":"publish",
"post_title":"[E_ALL] - All errors and warnings (includes E_STRICT as of PHP 5.4.0)",