Everybody Staze...

Nobody leavz...

  • Home
  • About Me
    • LinkedIn
    • Lab
  • Contact
  • Links
  • Reviews
  • Sitemap
  • Weather
You are here: Home / Archives for MySQL

PHP 5.6.4 upgrade (from 5.3.x) and MySQL 5.6

2014/12/31 By staze

PHP-MysqlI’ve been meaning to do this for a while, but a slashdot linked article about the large number of insecure PHP installs in the world got me off my ass to upgrade my stock Mac OS X php install from 5.3.x to 5.6.x. Thankfully, the process was pretty painless with the scripts provided here.

I did have to modify my http conf (since I’m not running a stock Apple install) to point to the new php, as well as set the new install location in my .profile, both of which were pretty easy. The biggest annoyance with the upgrade to PHP 5.6, however, was having to fix anywhere where objects were being set via reference “=&” rather than just =. So most of my PDO DB queries were being set via “$result =& $db->query(‘select blah from blah where blah’)”. This no longer worked with 5.6, as you can only set variables that way. Why I was doing it that way is because I’m a hack, and most of my PHP is copied and pasted from previous PHP I’ve done… so that practice just spread throughout. *shrugs* I also had to adjust some settings relating to APC no longer being supported, and opcache being the new PHP object cache setup. The real big change is, since I use W3TC, I had to DISABLE the Database and Object caches. Since these rely on no-longer supported APC calls, things would work fine for about an hour, then WordPress would just stop responding altogether (guessing when it would try to issue a garbage cleanup call) ((Sadly, the author of this plugin has been rather quiet about adding Zend opcache support)). Interestingly, my site sped up significantly after this change. Cool.

Since my server is a Mac, I had already been running MySQL 5.6 for some time (since OS X doesn’t ship with MySQL anymore), but I wanted to take this opportunity to “upgrade” all my tables from MyISAM to InnoDB. This, actually, was a bit more of a pain than I thought it would be.

[Read more…]

Filed Under: Coding Tagged With: 10.8.5, InnoDB, Mac OS X, Mountain Lion, MyISAM, MySQL, PHP

Twitter Tools bug (slow)

2009/12/31 By staze

UPDATE: Twitter tools 2.1 has been released, which fixes the issue described below. You may still need to run the code below to remove all the duplicates. Not sure if TT 2.1 does it automatically.

UPDATE 2: Looks like he did this by making the tw_id index “unique”. There may be other code changes elsewhere, but…

UPDATE 2b: Okay, so the “fix” is retarded. Basically, all they did was make the tw_id index “unique”. So, when Twitter Tools goes to add pre-existing tweets, the apache error log fills with errors about the index entry already existing. Rather than writing good code that just checks to see if the tw_id already exists, it just blindly tries to add it and fails when MySQL says “nope, already exists”. Heck, it COULD just only try to grab tweets posted since the last one downloaded. Either of these would be better than what it is doing. *sigh* If the code was better commented, I’d try to fix it myself… but my eyes cross when I look at it. =/

Quick post about an annoying bug with Twitter Tools.

There seems to be a bug with Twitter Tools 2.0 for WordPress, and unfortunately, the creator seemed rather un-interested in fixing it (instead just directing me to his pay-for site for WordPress support. =/).

Anyway, so, Twitter Tools, if you don’t know, keeps a database table of all the tweets you’ve written. It seems to check Twitter for posts each time it’s loaded, and if there’s a new tweet, it downloads it and adds it to the table.

Problem is, at some point, something changed (with Twitter I’m guessing), that made Twitter Tools re-grab ALL the tweets written by said user that are available on twitter’s site. In my case, that means it grabs 100+ tweets each time I tweet something and the page is loaded. So, the table in question quickly grows to a pretty large number of rows (I have about 475 tweets since I installed Twitter Tools, so the table should only be 475 rows. Instead, it had grown to 85,000 rows as of a few days ago).

Given the query used by Twitter Tools to show the latest tweets, looking at that many records can take a while. In my case, given my server, it took about 20 seconds (which slowed down my site by that much).

The query looks like this (this is assuming standard wordpress prefix, etc):

SELECT * FROM wp_ak_twitter WHERE tw_text NOT LIKE 'New blog post%' AND tw_text NOT LIKE '@%' GROUP BY tw_id ORDER BY tw_created_at DESC LIMIT 5;

Now, that’s a pretty slow query to run on 85k rows, but, not easily sped up. Easiest speed up, I guess, would be to add an index of the first 20 characters of “tw_text”, but that doesn’t really solve any problems, just speeds up the query. Adding an index for “tw_created_at” would help a bit too… but still, it’s 85k records, MANY (the vast majority) of which are duplicates.

First, are you impacted by this issue? Try this from the MySQL command line:

SELECT DISTINCT tw_id AS id,count(tw_id) AS idCount FROM wp_ak_twitter GROUP BY tw_id HAVING idCount > 1;

This should show you how many duplicates you have. If it comes back with nothing, then you’re good. But, I’d imagine you’ll be shocked by how many duplicates you have. Some of my tweets had around 500 duplicates.

So obviously, the first “fix” is to remove the duplicates. With some googling, I figured out the query looks like:

DELETE FROM wp_ak_twitter USING wp_ak_twitter,wp_ak_twitter AS vtable WHERE vtable.id > wp_ak_twitter.id AND vtable.tw_id = wp_ak_twitter.tw_id;

This basically creates a temporary table with the contents of wp_ak_twitter, then compares the row ID (which is unique, and a Primary Key), and then checks to see if the tweet ID is the same as any other rows. The first “where” basically keeps a row from matching itself. So, this will remove all duplicates and leave one original. After the above command, you’ll want to do:

OPTIMIZE TABLE wp_ak_twitter;

and

FLUSH TABLE wp_ak_twitter;

This will reduce the actual size of the table to what’s used by the remaining rows. Without this, the table will remain the same size as it was with all the duplicates.

But, this doesn’t really “fix” anything. It just removes the duplicates. The actual fix I haven’t quite finished yet. I’ll try to update this post in the next few days with a fix. But basically, it’s going to involve inserting a “SELECT” into the twitter tools code that checks for a tw_id before inserting the tweet.

Until then… good luck. Hopefully this will speed up your website if it’s been slow and you have twitter tools installed.

Filed Under: Sys Admin Tagged With: MySQL, plugin, Twitter Tools, Wordpress

Quick note

2009/09/19 By staze

So, just a quick note. I just updated the code for the power summary (which is on the left), and fixed the “current meter reading”. There were a couple issues, one of which was a bad sql query (not sure why the previous one didn’t work, but oh well), and for some reason, 2 days of data were missing (which you’d see if you clicked the “history”, and saw two “0” graph points.

Anyway, after fixing those problems, it turns out the “current meter reading” is dead on. I’m not sure how… and maybe it’s just a coincidence, but the meter reads exactly what the webpage says. Not too shabby. That means the drift for about 33 days is less than 1KWH, or less than about 300W per day, which given a 30KWH day, that’s less than 1% inaccuracy.

So, that’s it. Just thought I’d share. =) More actual interesting info later today, or tomorrow.

Filed Under: Coding, Energy Tagged With: MySQL, TED

Next Page »

Weather

Categories / Archives

  • Apple
  • Coding
  • Electronics
  • Energy
  • Home Ownership
  • Miscellany
  • Politics
  • Prius
  • Sys Admin
  • Travel
  • Uncategorized
  • Work
  • June 2026
  • April 2026
  • August 2025
  • April 2025
  • January 2024
  • February 2021
  • July 2020
  • January 2020
  • April 2019
  • March 2018
  • February 2018
  • June 2017

Copyright © 2026 · Staze On Genesis Framework · WordPress · Log in