Wordpress on Azure is really slow

I’ve recently set up a couple of WordPress blogs on Azure using the standard WordPress package from the Azure marketplace. Both times the sites have been really slow. The problem appears to be if you configure the database to a different region than the web app. Which is really easy to do because there’s no mySQL available on Australian Azure so you are told to pick the closest, which is SE Asia. Yet by default I always will add web apps onto Australian nodes. I thus wind up with the web app in Australia and the DB in Asia.

I experimented by spinning up a new WordPress with both the web app and database on SE Asia node – significant increase in speed.

If I have both internet and wifi enabled on my Apple Mac which connection is used?

I’ve long pondered this – if I have my MacBook connected both to ethernet and WiFi, which internet connection is it actually using?

In general sitting at my desk I want my Mac on ethernet, because speed-wise I see anything up to 100Mb down our cable connection. But I like having the WiFi on because then my iPhone and iPad are syncing in the background, and I don’t have to remember to turn the WiFi on and off as I move to and fro. However, the connection speed over the WiFi is slower, and I tend to see disconnects from my company’s VPNs although I could probably solve that with a bit of fiddling with the cable router configuration.

Finally I’ve tracked down the answer, and it’s simple.

Open System Preferences > Network. You’ll see a list of your connections on the left hand side. The active ones are green.

Screen Shot 2013-08-06 at 3.13.10 PM

The answer is, your Mac will use the connections in order – so if Ethernet is active and top of the list, that’s the connection used.

By default the order looks good to me – but you can change. Click the little ‘gear’ icon at the bottom of the list, there’s an option to change the order.

Screen Shot 2013-08-06 at 3.19.31 PM

Moving my blog from TypePad to WordPress

I’ve had a fun time the last couple of days moving this blog from its home of the last 5 or 6 years at TypePad, to WordPress.com. I made the decision for a number of reasons:

  • I’ve now used WordPress extensively over the past couple of years, and grown to love the software for its ease of use, configurability and flexibility. As an open source product, there is a vast community of contributors, an army of plugins and a battalion of really helpful users hanging out in forums. In contrast TypePad is a proprietary, closed ecosystem.
  • TypePad costs money. I’ve been paying them a subscription every month. WordPress.com is free, at least until I finalise the move by shifting my http://www.eedle.com domain, which I’ll sort out in the next week or two. It’s not that I begrudge paying money – completely the opposite given my line of work. But with TypePad I just didn’t feel I was seeing a significant innovation path. The software, in terms of the features I use, really didn’t feel it had moved forward in leaps and strides. By paying money to WordPress.com I’m supporting the development of a community-oriented product.
  • TypePad’s design templates are restricted and boring. I never really found a template I liked.I lack the design skills to create one for myself, and I’m not up for paying money to have one custom made for me. WordPress.com gives me a great set of templates, including the one I’m using now, which I think is a much more contemporary presentation than TypePad’s.
  • Finally, I actually have several other blogs on my WordPress.com account, for various businesses and ventures in which I am involved. My personal blog was the only thing I hosted at TypePad. For convenience it makes sense to keep everything together.

The actual move was pretty painless for those interested in the mechanics.

  • I exported my blog using the Export option in TypePad
  • I imported the blog (posts, comments etc) into WordPress.com using the specific TypePad import option. The only hitch with the import I’ve posted about in the forums – just an incorrect file extension, should have been .xml and not .txt. Although it would have been nice if the WordPress import page had validated this.
  • I had some problems with images. Some of the images were automatically scraped by WordPress – eg copied over from TypePad. Some were not. I’m not completely sure why this is the case, I think it’s something to do with the way TypePad hosts and names image files. They don’t look like image file URLs so perhaps WordPress didn’t recognise them as such. I wound up downloading a couple of dozen images by hand (eg Save As..) from TypePad and manually editing the posts in WordPress to update the image.
  • The text of the posts and comments came without any drama, although my ‘About’ page from TypePad turned up as a post in WordPress instead of a Page. Pretty minor, just a quick copy/paste.
  • All the Categories, and allocation of Posts to Categories arrived fine.

My one concern was for post URLs. On TypePad they all had an /eedle directory, because it didn’t actually have a domain in place, it was just http://eedle.typepad.com. I really should know better, but never got around to setting a domain up. Which meant I was faced with a bunch of URLs in Google, pointing to eedle.typepad.com – not much help if all the posts have moved over to WordPress.com.

So solution was to bite the bullet. I’ve pointed my www.eedle.com domain to TypePad, so that blog is now responding to that domain. I’ve never really used the domain for web pages – it’s mostly so I can have a cool email address like david@eedle.com.

I’ve submitted the URL to Google. I’ll use Google Webmaster Tools to tell Google to drop eedle.typepad.com URLs from the index.

We’ll let Google to its thing for a few days, by which hopefully all my pages in the index will be under http://www.eedle.com. Then I’ll move the domain over to the WordPress blog.

I know, I know, really what I should do is organise a 301 redirect on the TypePad URLs. (For the uninitiated this is an instruction to the search engines that the URL has changed).

Two reasons why I didn’t bother:

  • I actually cannot figure out a way to do this with TypePad in a way that is not a complete dodgy hack. Another fail for the software;
  • It doesn’t matter much. I don’t have a lot of traffic, I don’t have millions of inbound links. If someone is searching in the future, they’ll still find my pages.

SQL Server mqSQL “Commands out of sync; you can’t run this command now”

Scenario is:

1. You have a SQL Server db

2. You have a mySQL db

3. The SQL server db has a Linked Server connection to mySQL and you are using the mySQL Connector/OBDC

4. You try an insert or update statement in SQL server against the mySQL db using OPENQUERY

5. You receive the error "Commands out of sync; you can't run this command now"

To solve, uncheck the Forward Only Cursor option in the OBDC options.


How much do you love IE CSS problems!

Oh how I love working with IE browsers. Sure, IE6 is pretty much dead and buried – wasn't that a fun period in browser evolution – but now we grapple with IE7, IE8 and IE9. And the good folks at Microsoft at least have now been kind enough to add th F12 Developer Tools window where we can emulate back versions.

All this was thrown into stark highlight last week when I came across an interesting quirk, with someone running IE7, viewing an SSL secured page, containing a set of input fields, and styled using CSS that included a file called 'ie-css3.htc' from http://fetchak.com/ie-css3/.


Problem was he couldn't even move cursor focus onto thos fields, let alone type anything into the boxes. Everything was completely fine in every other browser and version and platform.

Turns out the author was prescient:

You will probably run into issues with z-index, especially if embedding one IE-CSS3 enabled element inside of another. There are two simple workarounds:

    Set the z-index of the IE-CSS3 element to a number larger than its surrounding elements.

We did just that, and changed the z-index of the input field class to 9999 instead of 0 and all was good.

It's the little quirks that make me laugh.



Calculate distance between web site visitor IP and list of locations

I’ve been having fun this morning writing code to calculate the distance between a web site visitor’s location, and a number of fixed locations, using the visitor’s IP number.

I have a list of events in different geographic locations. The idea is that when someone arrives at the web site we show them information about the event that is closest to them.

I’ve used a couple of tools to make this work.

First up I found the GeoLiteCity database from MaxMind. This is a free database that can calculate the longitude and latitude of an IP number. They say they cover the whole of the IPv4 system (and a fair chunk of the IPv6).

MaxMind does have a web service available (paid) but you can download the GeoLiteCity database and query it directly – they have a good set of example APIs. I’m using the COM object on a Windows server.

The database is a binary file that you reference via file path. They do supply a CSV to import into SQL but they make the point the binary is seriously faster, so unless you need additional access to the data, it’s not worth the loss of speed. If you also use the COM just take note of their instruction to rename the database file from GeoLiteCity.dat to GeoIPCity.dat. I have the file sitting just above the www root folder so it’s not visible to the world.

Finding the site visitor’s latitude and longitude is a doddle:

Dim geoip,visitorLat,visitorLong
set geoip = Server.CreateObject("GeoIPCOMEx.GeoIPEx")

I then hunted around online and found the longitute and latitude of the cities where my events are occuring – we’re not looking for ‘to the metre’ resolution here, just a quick guesstimate of which event and city is closest. When I get some more time I’ll sit down and figure out the coordinates of the actual venue for each event.

So now I need a way to calculate the distance between the visitor’s IP, and all of the events. Along the way I found this really useful page from Moveable Type  ‘Calculate distance, bearing and more between Latitude/Longitude points‘. It’s a great introduction to all the maths needed.

But another Google search found a forum post with a SQL stored procedure that calculates the distance between two coordinates, and it works well.

@FromLat float, @FromLong float, @ToLat float, @ToLong float
-- Function Name	: UDF_Distance
-- Description		: Returns distance in KM between two points on earth
-- Created by		: David Eedle
-- Created on		: 24 Jan 2011
-- Source:			: http://www.dbnewsgroups.net/sqlprogramming/t19131-sql-distance-between-latitude-longitude.aspx
declare @X float
SET @X =
* Sin(Radians(@ToLat))
+ Cos(Radians(@FromLat))
* Cos(Radians(@ToLat))
* Cos(Radians(@ToLong)-Radians(@FromLong))
SET @X = Acos(@X)
RETURN 1.852 * 60.0 * Degrees(@X)
select dbo.uf_Distance (41.63,-87.73,41.7,-88.07)

I used the Moveable Type page to double check the results and the procedure yields numbers within a few kilometres of MT’s answers over distances of 12,000km. If I was a maths whiz I’d probably now sit down for a day and figure out the inconsistency but I’m not trying to send a rocket to the moon so we’ll leave that for the experts.

Finally it was just a question of writing a quick query that pulls the coordinates of the events out, along with a calculation of the distance between the visitor and each event along the lines of:

SELECT cityId,cityName,cityState,cityDate,
CAST((select dbo.UDF_Distance ("&visitorLat&","&visitorLong&",V_ListCities.cityLat,V_ListCities.cityLong)) AS int) distanceKM
FROM V_ListCities ORDER BY (select dbo.UDF_Distance ("&visitorLat&","&visitorLong&",V_ListCities.cityLat,V_ListCities.cityLong))









ASP: Reading multiple recordsets from a stored procedure with ASP

Reading a recordset from a stored procedure is easy, essentially we just treat the procedure statement as the SQL statement, for example, something like:

sqlStr="USP_MyProc 1,2,3"
set rs=Server.CreateObject("adodb.Recordset")
rs.open sqlStr, conn, adOpenForwardOnly,adLockReadOnly

But how about reading more than one recordset from a procedure? Perhaps you have a circumstance where you need a couple of resultsets within the same code block. You could have more than one procedure and open each recordset in turn (or perhaps use the same procedure and control which resultset is returned using the procedure’s parameters).

Instead why not return all the required recordists from the one procedure using the one call to the database? It can be done, a procedure can return multiple recordists and each can be read in turn from your ASP code.

The trick is NextRecordset. You may already have been using this without quite realising, for example, when inserting a new record to the database that results in a unique identity value, we usually have a need to grab that value, so we’d do something like this:

sqlStr="INSERT INTO tblMyTable (myField) VALUES (myValue);"
Set rs = conn.execute (sqlStr & "select SCOPE_IDENTITY()").nextrecordset

If you look carefully you’ll see we’re actually running two queries, first the insert, and then a second to grab the identity. You can do the same with a procedure and multiple recordists. For example, let’s say you have a procedure that returns two recordists, you just cycle through them with NextRecordset:

sqlStr="USP_MyProc 1,2,3"
set rs=Server.CreateObject("adodb.Recordset")
rs.open sqlStr, conn, adOpenForwardOnly,adLockReadOnly
set rs2 = rs.NextRecordSet

Now you have the first results in rs and the second batch of results in rs2.