Thursday, February 5, 2015

PHP Sending mails twice?? (doing stuff twice)

Just had a mammoth troubleshooting session, because a very simple PHP script to send an email kept sending them twice. I’d only just configured postfix to send email, so I kept looking for problems there. I kept staring at the PHP code, and could see no problem, but it looked more and more like PHP was calling postfix twice. Commenting php.ini settings in and out made no difference. This was commandline PHP, so nothing to do with browser reloads, or anything like that.

Then I had the brainwave to append a random number to the bottom of the body text. Different numbers; in fact, not just that, but the 2nd email got both numbers! So it is definitely my PHP script. But I still couldn’t see it.

Stripped down, so the problem is more obvious, it looked like this:

$bodyText = "Whatever";

class Test{

function test(){
$bodyText.="RANDOM=".mt_rand(1,1000);
mail("me@example.com", "Test", $bodyText);
}
}

$R = new Test;
$R->test();

I’ve been spending too much time jumping between languages. And I’d also got used to PHP constructors being called __construct() and forget it still offered backwards compatibility for using the class name. Yep, that’s right, PHP functions (and classes) are case-insensitive, and so test() was being treated as the constructor of class Test. So one mail was being sent from the constructor, the second from my explicit function call. Grrrr….

(The above is also a possible explanation for problems like “PHP calls web service twice”, or “PHP has double log entries” or “PHP does something twice”!)

Written with StackEdit.

Sunday, October 19, 2014

Rackspace vs. AWS Oct 2014

I’ve previously blogged about Rackspace vs. AWS. For small servers, Rackspace has generally come out on top. But this year the pendulum has swung the other way.

First, Amazon released their t2.micro instance. The t1.micro was really just for learning the AWS API on, but the t2.micro is the kind of instance you can do real work on. (In fact I’ve been running the test version of a DB-backed website on one, for a month or two now, with no issues.)

A t2.micro server is $11.35/month in Ireland, ($15.64/month in U.S. East or Tokyo - I didn’t expect that! Europe cheaper than the U.S.!). This includes a 20GB magnetic disk, at about $1/month. (SSD is $2/month). $11.35 is £7.10/month (at today’s $1.60/£).

The second change this year is that Rackspace have introduced a compulsory service level fee, of £35/month. This is per data centre. (They might claim it is pay as you go, but small customers won’t do enough go-ing, so will always simply be paying £35/month.)

The third change is Rackspace have done away with their low-end servers. You used to be able to get a “next generation” 512MB server for 2p/hour (http://www.rackspace.co.uk/cloud/servers/existing-customer-pricing), and if you are an existing customer you still can. That works out at £14.40/month. The new minimum server is £52.52/month (including the £35 service level charge). (Of course, the new minimum server is higher spec., but as all I needed was the previous minimum spec, that does not matter.)

By the way, existing customers get a different pricing system, and don’t need to pay the service level charge. However, the per-hour prices are higher, e.g. for “Performance 1” (1GB RAM, 20GB SSD) it is £21.60/month, compared to £17.52/month (+£35) for new customers. (I guess this is related to their point - the service level was hidden in the prices, and now they’re just breaking it out… well, if the price was exactly the same, without the minimum fee, I’d have no problem with that.)

In Rackspace’s favour is their locations. They have a London data centre, the closest Amazon has is Ireland. They have a Hong Kong data centre, the closest Amazon can manage is Tokyo or Singapore.

In AWS’s favour, you have one account, globally, whereas with Rackspace it is one account per data centre.

BTW, one way they both make life difficult is by hiding their calculators. Here is AWS:
http://calculator.s3.amazonaws.com/index.html
And here is Rackspace UK’s:
http://www.rackspace.co.uk/calculator

So, to sum up, if all you need is minimum spec, Rackspace are now either £14.40 or £52.52/month (depending on if you are an existing customer at your desired data centre or not) while Amazon is now £7.10/month.

(Be aware that the prices are always in motion; but if you think I’ve misunderstood something above, please let me know in the comments.)

Written with StackEdit.

Monday, October 13, 2014

Fixing SVG font glyphs by hand

In a web font, I had one glyph where the background and foreground was reversed. Being Mr.Pragmatic, I just went with it, setting foreground and background colours appropriately. But it is an RWD site, and at certain scalings a 1 pixel white line was appearing. Here is how I fixed it.

I opened it in a text editor. What I had was:

<svg ... x="0px" y="0px" width="71px" height="67px" viewBox="0 0 71 67" enable-background="new 0 0 71 67">
<rect fill="#000000" width="71" height="67"/>
<g>
 <path fill="#FFFFFF" d="M49.562,...,31.799z"/>
 <path fill="#FFFFFF" d="M46,...z"/>
</g>
</svg>

The fix was as simple as deleting that <rect> line, and then setting the fill colour of the two <path> tags to be #000000.

When I made the webfont (I use the excellent icomoon.io site to do this) it looked fine. But it looked smaller than the other glyphs in the font. I can add padding easily with CSS, but removing it can be more work.

Conclusion: I don’t know how to do this. I could play around with the viewBox="..." in the <svg> tag, and change the appearance in Inkscape, but it made no difference in icomoon. Similarly, I could select the whole path, scale it in Inkscape, but still no change in icomoon. So, having done the important fix, I gave up on this one (and will stick to controlling the size and padding from CSS.)

Wednesday, September 24, 2014

Annoying keyboard shortcuts in Xfce

Quickie for mint16/17 using Xfce. You may have found the ctrl-Fn keys have been mapped to change the workspace you are on? This behaviour is highly annoying as applications often define ctrl-Fn to do something.

Do not try to fix it from the graphic configuration window. It does not work.

Instead, as root, open this file in a text editor:

/etc/xdg/xdg-default/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

(Because or links there are about three or four files pointing to this file; it doesn’t matter which one you edit.)

Look for lines like:

<property name="&lt;Control&gt;F5" type="string" value="..."/>

Then delete all those lines, there are 12 in total, from F1 to F12. (In my case they were not in a block, so you had to hunt around to catch all twelve.)

Then you need to logout of your desktop, and log back in again for the change to take effect.

Written with StackEdit.