Slow response testing localhost sites in Google Chrome on Mac OS X

Last week I noticed the response of localhost requests were slow in Google Chrome, but responded very quickly in Safari. I suspected Chrome was submitting my local requests to it’s data hunger servers to build an even better profile of me.
I tweaked a lot of Chrome settings so everything would be kept private, but no success. After several attempts I found the problem:

To test multiple sites and testing multi-domain rails applications I’ve changed my /etc/hosts file to contain the following items. nice-domain.local nice.sub-domain.local gamecreatures.local

So calling: “gamecreatures.local” in Chrome causes a too long delay for showing something..
calling “gamecreatures.local” in Safari responded instantly..

After doing some research, I’ve learned Apple is doing something special with the .local postfix. It is used by the Bonjour services somehow. I don’t know exactly what, but they do…

So changing all the extension from “.local” to something else for example “.loc” solved the issue for me: nice-domain.loc nice.sub-domain.loc gamecreatures.loc

Now Chrome also responds instantly…
Sorry Google for “assuming” you trying to steal all data from me… (Or should I use the _nomap extension for this one too ?!?)

Ruby on Rails / ChiliProject encoding issues

This week I’ve decided to exchange Redmine for the ChiliProject. The reason for this is the support for Ruby 1.9. My Apache Passenger server runs Ruby 1.9 so for Redmine I needed a seperate webserver.

When I tried to access the “My Account” page I recieved the following error:

ArgumentError (invalid byte sequence in US-ASCII):
  <internal:prelude>:10:in `synchronize'
  passenger (3.0.7) lib/phusion_passenger/rack/request_handler.rb:96:in `process_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:513:in `accept_and_process_next_request'
  passenger (3.0.7) lib/phusion_passenger/abstract_request_handler.rb:274:in `main_loop'
  passenger (3.0.7) ...
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop'
  passenger (3.0.7) lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously'
  passenger (3.0.7) helper-scripts/passenger-spawn-server:99:in `<main>'

Rendering /data/www/rails/chili/public/500.html (500 Internal Server Error)


How should I solve this? The chiliproject has an issue related to this:

The following Apache configuration fixed the issue: (The sample is on a FreeBSD system)

I added the following code to a file in the /usr/local/apache22/envvars.d/environment.env

export LC_CTYPE="en_US.UTF-8"

Problems I ruled out or fixed

While trying I also made sure the following things were configured:

I made sure the database is UTF-8. I re-created the database
an ran the migrations again.

create database chiliproject character set utf8;

I used the mysql2 connector instead of the mysql connector in database.yml

Apache 2.2.13 upgrade breaks my SSL configuration

Today I upgraded my Apache installation to 2.2.13 on my FreeBSD server. (Thankfully I first upgraded my internal server before upgrading the server this blog is on).
The server didn’t start:

[error] Server should be SSL-aware but has no certificate configured [Hint: SSLCertificateFile]

To solve this problem I usually fall back to google…

Finding some discussions about this problem I tried the following:
Moving the SSLCerticateFile and SSLCertificateKey outside a virtualhost tag as suggested, I’ve got the following error:

 [error] Illegal attempt to re-initialise SSL for server (theoretically shouldn't happen!)

More info wasn’t available…

After some debuggin/playing I found out I must remove ALL SSL stuff out of my directives except for the line SSLEngine ON.
So in short my config file :

# Those two lines are placed OUTSIDE the <virtualhost> tag
SSLCertificateFile /usr/local/etc/apache22/ssl.crt/server.crt
SSLCertificateKeyFile /usr/local/etc/apache22/ssl.key/server.key

# in a virtual host file:
&lt;VirtualHost *:443&gt;
  DocumentRoot /usr/local/www/sample

    SSLEngine on
   &lt;Directory /usr/local/www/sample &gt;
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all

Finally the sites are up again. Besides the Apache warning about SSL and virtual hosts everything runs find. PHeeew!

[warn] Init: You should not use name-based virtual hosts in conjunction with SSL!!

Now I must update this server, so If you can read this, the upgrade was succesful ;-)

Production gotcha: Rails send_file seems to corrupt files

What’s wrong with the following Rails code?

class ResourceController < ApplicationController  
  DEFAULT_OPTIONS = { :disposition => 'inline' }

  def send_file1
    send_file 'flash1.swf', DEFAULT_OPTIONS

  def send_file2
    send_file 'flash2.swf', DEFAULT_OPTIONS

This code works perfectly in development mode. In production mode retrieving the two different files the second file gets corrupt / wrong…

After a long search I looked in the rails code:

  def send_file(path, options = {}) #:doc:
    raise MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
    options[:length]   ||= File.size(path)
    options[:filename] ||= File.basename(path) unless options[:url_based_filename] 
    send_file_headers! options  

OOops… the send_file code modifies my class constant!
And after the first call the length and filename is placed in the class constant…
This is no problem in development mode because the classes are reloaded every time. In production mode every mongrel server has it’s own instance…

PHP’s Frustrating Flush

PHP not listening when you try to flush data. Try the following, it helped for me:

@ob_flush(); // try a normal flush

If PHP isn’t flushing it could be your webserver that’s collecting your output for gzipping:

mod_gzip_on no

This worked for me..