Skip to content

Instantly share code, notes, and snippets.

View matt-schwartz's full-sized avatar

Matthew Schwartz matt-schwartz

View GitHub Profile
@matt-schwartz
matt-schwartz / queue_worker_daemon.php
Created April 21, 2017 14:57
Template of an queue worker daemon
<?php
/**
* Queue worker daemon
*/
require_once __DIR__ . '/vendor/autoload.php';
// Throw an exception for all warnings, notices, etc.
function handle_err($errNo, $errStr, $errFile, $errLine)
{
throw new ErrorException("$errStr in $errFile on line $errLine", $errNo);
@matt-schwartz
matt-schwartz / daemon.php
Last active April 21, 2017 14:48
Template for a long-running PHP daemon process
<?php
/**
* Daemon process template
*/
// Throw an exception for all warnings, notices, etc.
function handle_err($errNo, $errStr, $errFile, $errLine)
{
throw new ErrorException("$errStr in $errFile on line $errLine", $errNo);
}
@matt-schwartz
matt-schwartz / shutdown_sequence.php
Last active January 20, 2017 17:55
Show PHP shutdown sequence
<?php
// Testing shutdown sequence
// Adapted from https://evertpot.com/160/
ob_start(
function($buffer) {
return $buffer . "output buffer flushed\n";
}
);
@matt-schwartz
matt-schwartz / postgres_tables_sizes.sql
Created July 27, 2016 20:34
PostgreSQL table sizes
SELECT *, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
, pg_total_relation_size(c.oid) AS total_bytes
, pg_indexes_size(c.oid) AS index_bytes