Here is a tidy javascript function that I found on stack overflow to mimic PHP’s usleep function which has been useful when testing javascript.
Continue reading “Php Sleep function in javascript”
An efficient alternative to paging with SQL OFFSETs
Paging large MySQL tables can be slow using the typical offset method. This alternative method leveraging the primary key is a more efficient solution.
Challenge
Running WordPress.com means having multimillion-record database tables. Tables which we often need to batch-query.
Provided we could hardly select (or update, etc) millions of records at once and expect speed, we commonly have to “page” our scripts to only handle a limited number of records at once, then move on to the next batch.
Classic, but inefficient, solution
The usual way of paging result sets in most SQL RDMS is to use the OFFSET
option (or LIMIT [offset], [limit]
, which is the same).
But on a performance level, this means you’re asking your DB engine to figure out where to start from all on its own, every time. Which then means it must be aware of every record before the queried offset, because they could be different between queries (deletes, etc). So the higher your offset number, the longer the overall query will take.
Alternative solution
Instead, of…
View original post 126 more words
How to debug your WordPress plugin
If you are developing a plugin on WordPress, you will need to debug your code as you go.
To enable debugging, go to your wp-config.php file.
Find the line…
define('WP_DEBUG', false);
Replace the line above with the following…
// Turns WordPress debugging on define('WP_DEBUG', true); // Tells WordPress to log everything to the /wp-content/debug.log file define('WP_DEBUG_LOG', true); // Doesn't force the PHP 'display_errors' variable to be on define('WP_DEBUG_DISPLAY', false); // Hides errors from being displayed on-screen @ini_set('display_errors', 0);
Now you all warnings and errors will show up in the /wp-content/debug.log file, including WordPress warnings of deprecated functions.
You can write directly to this log from your plugin using the error_log()
function.
Typically…
//output some debug string error_log( 'this works yo' ); //output some array/object error_log( print_r( $some_obj_or_array, 1 ) );
Kudos to this post. It has some good plugin development tips, including how to enable debugging on WordPress.
WP Plugins: How to remove a Filter
Do not use
remove_filter()
. It is possible it will break other hooks which can have unintended consequences. This post gives a really good alternative approach using static variables.
Worth to know for wordpress plugin authors: Making your plugin to safely unregister or remove a hook (filter or action) is not possible with the wordpress plugin API. Why? you might ask yourself. Even the name of the remove_filter() function suggests it and the codex documentation does say so as well.
But: It does not work, because this function does not work as intended. And beyond your own hooks, it has the potential to hinder the blog from working properly as it has the potential to remove other hooks then the specified one.
Does not is not exactly right, it does, but only sometimes. That’s specifically a bummer if you write plugins yourself, because you can not safely rely on it. For example, if running your plugin makes use of PHP 5.2 or greater it works. But it does not if it’s running on PHP 4 or PHP 5 lower…
View original post 1,582 more words
How to request just the response headers with cURL
Here is the cURL config to request just the response headers with the cURL library
Continue reading “How to request just the response headers with cURL”
How to Auto-Forward Gmail Messages in Bulk
Unfortunately, Gmail will not allow you to forward old email via a filter.
I found a way that you can transfer all email from one Gmail account to another, and it works but it’s a tad complicated.
If you want to simply forward old email, the solution from Digital Inspiration using Google Docs is better.
Continue reading “How to Auto-Forward Gmail Messages in Bulk”
Magpie Lane
Search Associative Array with Wildcard in PHP
Here are a pair of functions that will allow you to search an associative array for either a key or a value, using a string with a wildcard (*).
Continue reading “Search Associative Array with Wildcard in PHP”
Change SVN editor to Vim or TextWrangler
When you check-in to SVN with svn ci
, the default editor opens to allow you to enter your commit message. My default editor was Emacs. I don’t use Emacs for anything else, and I found entering a simple message a tad frustrating as Emacs commands/shortcuts are different to what I use with Vim.
Continue reading “Change SVN editor to Vim or TextWrangler”
Get last character in a string using PHP
Similar to how you get the last character in a string using Javascript, you just slice off the last N characters.
Continue reading “Get last character in a string using PHP”