Friday, September 17, 2010

$GLOBALS or global?

I recently upgraded to Ubuntu 10.04 which includes php 5.3.2. Not long after upgrading, I noticed that transactions in my stock tracking program were no longer sorting correctly. At first, I thought the sort function, uksort, might have subtly changed. But, no, the manual didn't mention anything, and the manual and comment examples appeared to line-up with my code nicely.

Next, I checked the apache error log where I got my first clue as to the madness I was about to uncover:

PHP Warning:  uksort(): Array was modified by the user comparison function in ... on line 195
I double-checked my code. Nope. No modification of the array being sorted. What gives? I was using a global statement so that I could access the array being sorted...

A Google search on the global statement turned up another way to access global variables, the $GLOBALS array. Could php be overzealously assuming that access of a variable via a global statement constitutes modification? Well, maybe using $GLOBALS would solve that problem.

I switched from global to $GLOBALS, and, voila, sorting worked again! Apparently php does equate using a global variable via the global statement to modification of that variable. Geez!

P.S. uksort was returning a false value indicating that the sort had failed.

Thursday, January 7, 2010

GoDaddy disallows 3rd party SMTP relay

My wife has been using GoDaddy to host her web site, Helen's Kitchen, for about four years now. She's generally been happy with it. That is, until now.

First, I should clarify. The web and mysql server services provided by GoDaddy are still solid---besides occasional slowness and an occasional brief outage, there has been little to complain about (though wading through the 1000 useless offers in order to do anything on the GoDaddy site is a bit of a pain). The problem has been with email relaying. Helen's site sends her and customers email(s) when users sign up for classes. Once or twice in the past, there have been multi-hour email backups where emails would not be sent from GoDaddy's servers until many hours after they were entered into the mail queue by Helen's web site. These were annoying, but GoDaddy was responsive and addressed the problem fairly quickly.

E-mail is once again a problem. But, whereas GoDaddy has fixed the problem quickly in the past, Helen is now waiting on emails that were queued 4 days ago. And, it is very clearly a problem of GoDaddy simply getting the messages out-the-door and not due to intermediate servers. As of 2 days ago, GoDaddy had officially recognized the problem and was "working on it." But, the problem still hadn't been resolved as of late last night. Our first response was to seek a 3rd party SMTP relay provider. But after signing-up with AuthSMTP, and running a successful test from my home machine, we learned that GoDaddy blocks all outgoing TCP connections from their shared web hosting servers, making it quite challenging to send email via a 3rd party provider.

GoDaddy representatives keep telling us that we should just upgrade to a virtual dedicated server (for 5x the price!). This would allow us to make outgoing TCP connections. But, a quick chat with a justhost representative indicates that they would allow an outgoing TCP connection (so that we could do 3rd party SMTP relaying) once we convince them we aren't going to use it to spam. So, I don't understand why we should pay GoDaddy more money when the level of service seems to be falling. What I find especially surprising about all this is that the requirements for my wife's web site are tiny: 1000s of uniques/month; the entire database is less than 100k uncompressed. So, we might just have to switch to another web provider...