the most awesome guy ever.

The Blog of Darryl E. Clarke

  Random musings from a jaded coder who just needs a hug.

Posts Tagged ‘apache’

Allowing the Facebook Debugger Through .htaccess

Thursday, November 1st, 2012

Here’s a short story; When I develop Facebook web apps, I do it under a password protected development site. Facebook hates this. It complains that it can’t reach urls, it can’t get meta data, it can’t do this, it can’t do that. The downside to not having a password is the fact that anybody can hit the site. (sandboxing is almost useless, these days.)

So, the quick solution: Allow Facebook to hit it, but only via their external meta data scraper.

A quick edit (well, not so quick, it was something obscure.) of my .htaccess rules, and voila! Facebook can debug and people still can’t hit it (easily)

SetEnvIf User-Agent ^facebookexternalhit.*$ Facebook=1

AuthType Basic
AuthName "Art & Science DEV Server"
AuthUserFile /home/dclarke/www/dev/.htpasswd
Require valid-user

order allow,deny
Allow from env=Facebook
Satisfy Any

First, set an environment variable based on if it is the Facebook user agent. Then, allow access. The key here is the ‘satisfy any’ line, which means you can get in if you have a user and password, or that environment flag is set. The downside is now you all know you can just set your user agent to Facebook and get access to my dev sites. 😉

Tags: , ,
Posted in Coding

The Switch: Apache + Mod_PHP to Nginx + PHP-FPM

Thursday, December 22nd, 2011

File this under “another thing I should’ve done ages ago.”

I decided that I should explore the world of Nginx as a web server since many people have been telling me it’s good. And all I can say is holy shit, it’s good. The setup was simple and after a few idiotic mistakes on my part, it was up and running.

At first I was skeptical as to how fast it would be and with my first couple of benchmarks, nginx was definitely faster.. but not by much. With just a simple php file on a very low resource machine (Ubuntu 11.10, on a 256MB VM at rackspace which I use for playing around) I used ‘ab’ to test 1000 requests with 10 concurrent:

Nginx:
Concurrency Level:      10
Time taken for tests:   0.473 seconds
Complete requests:      1000
Total transferred:      191000 bytes
HTML transferred:       26000 bytes
Requests per second:    2112.79 [#/sec] (mean)
Time per request:       4.733 [ms] (mean)
Time per request:       0.473 [ms] (mean, across all concurrent requests)
Transfer rate:          394.09 [Kbytes/sec] received

Apache:
Concurrency Level:      10
Time taken for tests:   0.533 seconds
Complete requests:      1000
Total transferred:      245000 bytes
HTML transferred:       26000 bytes
Requests per second:    1877.53 [#/sec] (mean)
Time per request:       5.326 [ms] (mean)
Time per request:       0.533 [ms] (mean, across all concurrent requests)
Transfer rate:          449.21 [Kbytes/sec] received

As you can see from the initial benchmark, there’s not much difference, but it is noticeable. And if you throw even more at it I’m pretty sure the gap will be bigger.  One thing that stood out most to me is the extra amount of data that Apache sends.

After I setup a zend framework application, I ran the benchmarks again. Same 10 concurrent, 1000 requests:

Nginx:
Concurrency Level:      10
Time taken for tests:   15.892 seconds
Complete requests:      1000
Total transferred:      3735000 bytes
HTML transferred:       3577000 bytes
Requests per second:    62.92 [#/sec] (mean)
Time per request:       158.922 [ms] (mean)
Time per request:       15.892 [ms] (mean, across all concurrent requests)
Transfer rate:          229.51 [Kbytes/sec] received

Apache:
Concurrency Level:      10
Time taken for tests:   17.724 seconds
Complete requests:      1000
Total transferred:      3791000 bytes
HTML transferred:       3577000 bytes
Requests per second:    56.42 [#/sec] (mean)
Time per request:       177.242 [ms] (mean)
Time per request:       17.724 [ms] (mean, across all concurrent requests)
Transfer rate:          208.88 [Kbytes/sec] received

Again, the difference is there. Nginx is clearly faster. It’s clearly winning. But I’m still just benchmarking with settings that I know Apache can handle on the low resource box. And this of course is all about resources and effectively using them. So I pumped it up. Time to do ab -c 100 -n 10000, ten thousand requests with one hundred concurrent and the results are amazing:

nginx:
Concurrency Level:      100
Time taken for tests:   122.030 seconds
Complete requests:      10000
Total transferred:      37350000 bytes
HTML transferred:       35770000 bytes
Requests per second:    81.95 [#/sec] (mean)
Time per request:       1220.301 [ms] (mean)
Time per request:       12.203 [ms] (mean, across all concurrent requests)
Transfer rate:          298.90 [Kbytes/sec] received

Apache:
CRASHED after 485 requests.
apr_poll: The timeout specified has expired (70007)
Total of 485 requests completed
load average: 83.73, 30.80, 11.43

The server load under apache went into a state of pure cluster-fuck. Apache could not contain itself with 100 concurrent connections on a box with such low resources, whereas Nginx handled it with EASE. The requests per second were slightly slower at 81.96 when doing 100 concurrent connections, but that request count is still amazing compared to apache crashing.

I’m sorry Apache+mod_php, you lose. Now it’s time to migrate all my stuff.

Tags: , , ,
Posted in Linux, PHP, Ubuntu, Zend Framework

A Pinch of Performance (Apache Tuning)

Wednesday, March 31st, 2010

If you’re using rewrite rules and other special configuration directives on your website, like any Zend Framework site does, you might want to consider the following:

Avoiding .htaccess and ‘AllowOverride [not none]’ on large websites.
(more…)

Tags: , , , ,
Posted in Randomness

Summer Project: Status Update

Tuesday, June 23rd, 2009

I’ve managed to get my little test server all configured for each path.  This little task involved configuring mod_ruby, mod_perl, mod_python on top of my already standard php. I also had to fire up mod_proxy to mask the jsp directory (which is really going to an apache tomcat server – another box on my network).

You can view the progress as I start building.  Progress is still fairly slow at this moment. But now that all the frameworks are in place and my apache ninja skills have been revived I should be able to kick it up a notch.

I’ve also made a slight change in how I’ll be storing the images in the database.  I’m going to just be doing a plain old base64 encode of the binary data.  I’d much rather just store binary data in the database as a central repository for all paths, but there appears to be some issues with this and the fact that the entire django community hates binary data in a database.  So I’m not going to fight it or waste any more time on it.

Tags: , , , , , , , , , , , , , , , , ,
Posted in Randomness

Summer Project Details

Sunday, May 3rd, 2009

As part of my previous post, “things to do this summer,” I’ve decided on a not so clever appraoch to proving to myself that “it’s just a language.”

What do I mean by, “it’s just a language?”  Well, let me tell you. On a regular basis I get asked “do you now [language]?” And my answer is usually something along the lines of “Well, I know of it, I’ve touched it a bit, but never done anything real with it.”  But, since I’m a programmer I usually follow it with “It’s just a language.”  So now I’m going to prove to myself that it is in fact “just a language.”

(more…)

Tags: , , , , , , ,
Posted in Coding

Zend Framework, Rewrite Rules, Apache

Tuesday, September 23rd, 2008

Most of the Zend Framework documentation I’ve read recommends a rewrite rule that looks something like this:

RewriteEngine on
RewriteRule !\.(swf|js|ico|gif|jpg|png|css)$ index.php

Why not use a more elegant rule that looks like this:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php

This rule basically says: If it’s not an existing file, and it’s not an existing directory – pass the request through index.php.

This allows you far more flexibility when you want to host non-framework files, or a whole slew of other media types that are not listed in your apache configuration.

Tags: , ,
Posted in PHP, Zend Framework