Monday, April 25, 2011

How To Get Around The New York Times Paywall

The New York Times will now allow you to see a limited number of articles (20?) before "enforcing" a paywall, showing you a preview of each article and pointing you toward a subscription page. But, this paywall is about as leaky as a BP blowout preventer. Search for the title of the article on Google News, click the first link, and, voila! Paywall removed. Apparently, the NYTimes wants to have its cake and eat it too. They want to keep all the revenue generated by ads and search traffic, and add a paid subscription revenue stream. I pay $5/year for ad-free access to The Wunderground. I don't see why I should be paying almost $200/year for a subscription that doesn't even get rid of the ads, especially when I can find comparable content elsewhere...

Tuesday, April 5, 2011

Rewriting the Envelope "From" Address

I use AuthSMTP for mail delivery when sending automated emails via my web server. Recently, I noticed that they were failing:

Real domain name required for sender address (in reply to MAIL FROM command)
The web server was using www-data@localhost as the envelope "from" address and AuthSMTP didn't like such a bogus domain.

While reading/searching the postfix documentation, I discovered that postfix can rewrite such local/bogus email addresses automagically. See the section on Generic mapping for outgoing SMTP mail.

But postfix died after I customized the example and tried to restart postfix. The example forgot to mention that the mapping needs to be encoded in a database format in order for postfix to read it. After you create a file named generic in /etc/postfix, you need to run:

sudo postmap hash:generic
from the /etc/postfix directory. This will create a Berkeley DB file with the same information as your plain-text file.

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...

Monday, October 12, 2009

Better access to properties/attributes

Iterating through an object's properties/attributes is something you can easily do with __dict__ in Python. PHP doesn't automatically give you this feature, but you can build it in via the __get and __set overloads. It requires that you follow a certain class definition pattern, but it should not be hard to add this pattern after a class is established:
class Foo {
  private $data = array();
  function __get($k) {
    return $this->data[$k];
  }
  function __set($k, $v) {
    $this->data[$k] = $v;
  }
  function __isset($k) {
    return isset($this->data[$k]);
  }
  function __unset($k) {
    unset($this->data[$k]);
  }
}
The $data attribute acts as the object itself; __get and __set translate between object property and array entry requests. __isset and __unset handle sset() and unset() calls (only PHP 5.1.0+). Documentation can be found in the Overloading section of the PHP manual. Once you've implemented this pattern, it's trivial to access the object's attributes as an array which means that it's easy to iterate over entries.