Alexey Zakhlestin's Blog

Programming for Mac and Web

SMTP Legacy

Permalink

Some things still wonder me, after 10+ years of web-development. Todays wonder is here:

RFC2821 (SMTP) tells: The maximum total length of a text line including the is 1000 characters. In real world, most MTAs default to 990 characters per-line, which means, that if you will try to dump longer line on them, they would split it by putting ”!\n” after 990-th byte. This is mostly harmless for plain-text, but can easily break html.

Actually, there is even a PHP-bug reported, regarding this, but PHP obviously can’t do anything to help the situation

The solution is really simple: if there is a chance, that lines of your emails would be longer than 990 bytes encode body using base-64. The easiest way to do it for emails without attachments, in php is to use mb_send_mail() function instead of mail(), as it will apply encoding automatically.

The Shortcut to Switch Tabs Is…

Permalink

The shortcut to switch tabs is…

TextMate:

Command + Option + Left/Right

Skype:

Command + Shift + Left/Right

Adium, Firefox:

Command + Left/Right

Colloquy, Firefox:

Command + Up/Down

Opera, Safari, Terminal:

Command + Shift + [/]

Dear Santa, please, bring me Mk 41 next christmas, so I can fix this world.

Syck 0.9.2

Permalink

I’ve just released syck for php 0.9.2 (a parser and emitter of YAML documents. If you don’t know anything about YAML and why it is good: check my previous posts on the subject). A lot of new and tasty features ;)

First, and most important: a lot of stability and consistency fixes (previous release wasn’t properly dealing with some kinds of number-like strings and with mixed-keys arrays). This release is HIGHLY recommended to anyone who uses syck-php in production. I was using this version for several weeks as a server-to-server exchange format under heavy load and coudn’t be satisfied more.

I started to dive into object-serialization and unserialization topics. Any object which implements Serializable interface can be dumped into yaml-document now. It will be stored using !php/object::ClassName signature. And, of course, you would be able load the object afterwards. Important: at the moment of loading yaml-file, all of the classes mentioned in it have to be either declared, or be available to php’s autoload mechanism.

I also implemented loading of objects with !php/array::ClassName and !php/hash::ClassName signatures. These have to implement ArrayAccess interface. Unfortunately, I didn’t implement dumping of such objects yet. That is planned for the next releae.

As always, I am open to hear any of your comments and bug-reports.

All Those IIS Talks

Permalink

Looks like almost every planet-php blogger mentioned that FastCGI for IIS thingie. I wonder: was it really that bad before it came? The thing which disturbes me in all this hype is that people will tend to think that fastcgi is something iis-specific. Hope they won’t, because fastcgi is a good (and really powerful) way to run PHP applications even if you use apache.

Top reasons:
1. FastCGI process can be run using the actual uid of user who creates the files (no need to allow group-readability of files)
2. Apache2 can be run in multithreaded-mode (aka ”worker mpm”)
3. It is much easier to switch to any other server (fastcgi is an industry standard and works with any web-server software I know of)
4. It is much easier to scale — fastcgi-application can be moved to another physical server and http-server will still be able to talk with it

FastCGI is about flexibility and it deserves a lot of good words not only in IIS context :)

Ip2long, 32-bit/64-bit

Permalink

It is a common practice, to use ip2long() function for getting integer-representation of ip-address (for database-storage).

Problem:

on systems with 32-bit integers, ip2long() returns values from -2147483648 to 2147483647

on systems with 64-bit integers, ip2long() returns values from 0 to 42949672945

Which means, that if you were using INT as a storage type on 32-bit server, you will need to change that field to be UNSIGNED INT (or BIGINT) on 64-bit server.

There is no simple migration, sorry.

p.s. similiar problems can appear in other intger-related functions too

Syck vs. Spyc (Benchmarking)

Permalink

Regarding syck vs. spyc debate which seems to appear again and again:

al_n @ [link]:

I re tested syck and it does make a BIG difference. I tested with a yaml file of about 200,000 lines which I killed after an hour while using spyc. The same file was loaded with syck in about 5 minutes!!!

p.s. I hope to find some time, to release an updated pecl-package of syck really soon. Please, remind me to do it ;)