While driving today I noticed some really strong sun dogs and I just had to take a picture 🙂
It’s edited a little bit to help make it clearer through my car window, but it was still awesome!

Like last time, I’ve come into ownership of a suspicious flash drive that holds a secret: It’s actually a micro SD card and reader… and completely broken 🙂


Warning: Only 120992 of 120993 MByte tested.
The media is likely to be defective.
33.1 GByte OK (69490999 sectors)
85.0 GByte DATA LOST (178300617 sectors)
Details:371.5 KByte overwritten (743 sectors)
0 KByte slightly changed (< 8 bit/sector, 0 sectors)
85.0 GByte corrupted (178299874 sectors)
371.5 KByte aliased memory (743 sectors)
First error at offset: 0x0000000848b26e00
Expected: 0x0000000848b26e00
Found: 0x286fe2ee6fa575a5
H2testw version 1.3
Writing speed: 9.79 MByte/s
Reading speed: 3.36 MByte/s
H2testw v1.4




If you’re hosting your WordPress website on DreamHost, and use their cron system to offload your WordPress faux-cron for better reliability, be careful of what version of PHP you have in your code.
I recently had an issue where my cron events weren’t firing, and after enabling email output, I ended up with something like this PHP error message:
Parse error: syntax error, unexpected '?' in /path/to/file.php on line 123
It turns out that WP-CLI was running PHP 5.x via the DreamHost cron system. I had PHP 7.x specific code in my theme.
To fix this, I had to set the WP_CLI_PHP environment variable in my cron job:
export WP_CLI_PHP=/usr/local/php72/bin/php
wp cron event run --due-now --path=/home/path/to/wp/ --url=https://example.com/Code language: JavaScript (javascript)
WordPress has a built-in function called wp_safe_redirect(). This allows you to create redirects in code, but only to whitelisted domains (via the allowed_redirect_hosts filter).
The downside to this is that you have to remember to whitelist the domains. It’s easy to forget if you’re doing a lot of redirects, for instance with the WPCOM Legacy Redirector plugin.
When this happens, all un-whitelisted redirects will be redirected by default to /wp-admin/ instead, and can cause a headache trying to figure out what’s going wrong.
I had an idea to solve this problem. A simple logging plugin that logs failed redirects and adds a dashboard widget to show the domains and number of times the redirect has failed:

The code behind this:
<?php
class Emrikol_WSRD_Dashboard {
public static function instance() {
static $instance = false;
if ( ! $instance ) {
$instance = new Emrikol_WSRD_Dashboard();
}
return $instance;
}
public function __construct() {
add_action( 'init', array( $this, 'init' ) );
add_filter( 'allowed_redirect_hosts', array( $this, 'check_redirect' ), PHP_INT_MAX, 2 );
}
public function init() {
if ( $this->is_admin() && isset( $_GET['wsrd_delete'] ) && check_admin_referer( 'wsrd_delete' ) && isset( $_GET['ID'] ) ) {
$post_id = (int) $_GET['ID'];
if ( 'wsrd' !== get_post_type( $post_id ) ) {
// This isn't the right post type, abort!
add_action( 'admin_notices', array( $this, 'message_log_not_deleted' ) );
return;
}
$delete = wp_delete_post( $post_id, true );
wp_cache_delete( 'wsrd_report' );
if ( $delete ) {
add_action( 'admin_notices', array( $this, 'message_log_deleted' ) );
} else {
add_action( 'admin_notices', array( $this, 'message_log_not_deleted' ) );
}
}
$args = array(
'supports' => array( 'title' ),
'public' => false,
);
register_post_type( 'wsrd', $args );
add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) );
}
public function add_dashboard_widgets() {
if ( $this->is_admin() ) {
wp_add_dashboard_widget( 'emrikol_wsrd_dashboard', 'Failed Safe Redirects', array( $this, 'show_admin_dashboard' ) );
}
}
public function check_redirect( $allowed_hosts, $redirect_host ) {
if ( ! in_array( $redirect_host, $allowed_hosts, true ) ) {
// No redirect, please record.
$found_host = new WP_Query( array(
'fields' => 'ids',
'name' => md5( $redirect_host ),
'post_type' => 'wsrd',
'post_status' => 'any',
'no_found_rows' => true,
'posts_per_page' => 1,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
) );
if ( empty( $found_host->posts ) ) {
// No past redirect log found, create one.
$args = array(
'post_name' => md5( $redirect_host ),
'post_title' => $redirect_host,
'post_type' => 'wsrd',
'meta_input' => array(
'count' => 1,
),
);
$insert = wp_insert_post( $args );
} else {
// Found! Update count.
$count = absint( get_post_meta( $found_host->posts[0], 'count', true ) );
$count++;
update_post_meta( $found_host->posts[0], 'count', $count );
}
}
// We don't want to modify, always return allowed hosts unharmed.
return $allowed_hosts;
}
public function show_admin_dashboard() {
global $wpdb;
$report = wp_cache_get( 'wsrd_report' );
if ( false === $report ) {
$report = $wpdb->get_results( "SELECT ID, post_title AS host, meta_value AS count FROM $wpdb->posts LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id ) WHERE post_type='wsrd' ORDER BY ABS( count ) DESC LIMIT 20;" );
wp_cache_set( 'wsrd_report', $report, 'default', MINUTE_IN_SECONDS * 5 );
}
?>
<style>
table#wsrd {
border-collapse: collapse;
width: 100%;
}
table#wsrd th {
background: #f5f5f5;
}
table#wsrd th, table#wsrd td {
border: 1px solid #f5f5f5;
padding: 8px;
}
table#wsrd tr:nth-child(even) {
background: #fafafa;
}
</style>
<div class="activity-block">
<?php if ( empty( $report ) ) : ?>
<p><strong>None Found!</strong></p>
<?php else : ?>
<table id="wsrd">
<thead>
<tr>
<th>Domain</th>
<th>Count</th>
<th>Control</th>
</tr>
</thead>
<tbody>
<?php foreach ( $report as $line ) : ?>
<tr>
<td><?php echo esc_html( $line->host ); ?></td>
<td><?php echo esc_html( $line->count ); ?></td>
<td><a href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'wsrd_delete' => true, 'ID' => rawurlencode( $line->ID ) ), admin_url() ), 'wsrd_delete' ) ); ?>">Delete</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<?php
}
public function message_log_deleted() {
echo '<div id="message" class="notice notice-success is-dismissible"><p>Redirect log deleted!</p></div>';
}
public function message_log_not_deleted() {
echo '<div id="message" class="notice notice-error is-dismissible"><p>Redirect log delete failed!</p></div>';
}
private function is_admin() {
if ( current_user_can( 'manage_options' ) ) {
return true;
}
return false;
}
}
Emrikol_WSRD_Dashboard::instance();
Code language: HTML, XML (xml)
Something that I do often at work is to check HTTP headers for random things such as redirects, cache headers, proxies, ssl, etc.
A common way this is done is by using the -I (--header) switch:
$ curl -I http://example.com/
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Wed, 27 Jun 2018 22:03:57 GMT
Etag: "1541025663+gzip"
Expires: Wed, 04 Jul 2018 22:03:57 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (atl/FC94)
X-Cache: HIT
Content-Length: 606
Code language: JavaScript (javascript)
The downside to this is that it uses an HTTP HEAD request, which can sometimes return different headers or different information than a standard GET request. This can be fixed by using the -X (--request) switch. This overrides the default HEAD?request with whatever you choose:
$ curl -I -XGET http://example.com/
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: max-age=604800
Content-Type: text/html
Date: Wed, 27 Jun 2018 22:07:47 GMT
Etag: "1541025663"
Expires: Wed, 04 Jul 2018 22:07:47 GMT
Last-Modified: Fri, 09 Aug 2013 23:54:35 GMT
Server: ECS (atl/FC90)
Vary: Accept-Encoding
X-Cache: HIT
Content-Length: 1270
Code language: JavaScript (javascript)
I like to just combine them into one quick command: curl -IXGET http://example.com/

The WordPress WP-Cron system is a decently okay faux cron system, but it has its problems, such as running on frontend requests and not running if no requests are coming through.
WP-Cron works by: on every page load, a list of scheduled tasks is checked to see what needs to be run. Any tasks scheduled to be run will be run during that page load. WP-Cron does not run constantly as the system cron does; it is only triggered on page load. Scheduling errors could occur if you schedule a task for 2:00PM and no page loads occur until 5:00PM.
From the WordPress Plugin Handbook
These are problems because:
The solution to this is to disable the built-in cron firing that’s done with pageviews, and use a system cron (or other service) to poll for cron events.
Disabling the cron firing is done by adding this to the wp-config.php file:
define( 'DISABLE_WP_CRON', true );Code language: JavaScript (javascript)
For this site specifically, I use the “Cron Jobs” system of DreamHost to run this WP-CLI command every 10 minutes:
wp cron event run --due-now --path=/path/to/derrick.blog/ --url=https://derrick.blog/Code language: JavaScript (javascript)
This forces the cron to run and check for ready jobs every 10 minutes. It’s possible that some cron events might run later than they “should” but in practice, I’ve seen this running more cron jobs than if I relied on page loads.