Toby's Log page 94

Symfony AppCache and ‘X-Reverse-Proxy-TTL’, a hack

Symfony’s HttpCache reverse proxy is a simple way to get caching of pages with Symfony. It is simple to set up, easy to work with, and easy to clear. I started using it recently on my own site.

A simple app/console cache:clear will clear the entire cache. Otherwise, following the HTTP-oriented spirit of the framework, invalidation is based entirely on HTTP headers. In this way, it works the same as proxy / gateway caches. It only caches responses with public Cache-Control headers. It is age based, using the Cache-Control s-maxage or maxage values or Expires headers (following that order of precedence). It then considers the cached items fresh until they are stored for longer than those headers specify they can be stored. The cached version is served, bypassing the router / controller, as long as the cache is fresh.

This is all nice, but using long max-ages for those headers means that caches outside of my control can cache pages for long periods of time. cache:clear won’t help when a page changes. One possible option would be to have shorter and safer max-ages as Cache-Control headers and use something else for HTTPCache.

Continue reading post "Symfony AppCache and ‘X-Reverse-Proxy-TTL’, a hack"

404 with autofilling form

Inspired by a tweet by @simevidas about a 404 page search form, I decided to finally replace Symfony’s default 404 page on my site. The tweet was about an example site’s 404 pages that take pieces from the URL path to populate a search field. Upon seeing it, I immediately thought how easy it would be to implement a simple version of that.

I had been thinking of customizing my 404 for a while, but stopped trying because Twig doesn’t seem to know about bundle paths in the error pages, preventing me from extending the “base” template in my bundle. I still didn’t find a solution for this, so the 404 page has an unstyled look, but I wanted to capture the search form idea while it was on my mind.

Looking into 404 best practices, I found three things that I wanted on mine: branding, guidance / next steps for the user, and small size / low power.

Continue reading post "404 with autofilling form"

Websites in Multiple File Formats

Since I saw Symfony’s _format routing parameter, which is used to effectively set the file type of the response, I’ve thought it would be cool to have every page on a website support more than just ‘html’ response types by adding a .{_format} to the end of the URL and make a template version for each. Users would be able to consume the same information in different formats depending on their needs. ‘txt’, for example, would basically have just the content that would go in the <main> element, in pure text format, providing a fallback or simplified view that can be read even by curl users. ‘json’ or ‘xml’ formats might provide the content and meta data about it in a machine consumable format. You could even go all out with an ‘mp3’ format where you read the page content.

Yesterday, I took my first step toward this idea on my site by implementing my homepage in the ‘txt’ format. This was very simple since my content is already being composed in markdown, a visually pleasing structure for text content.

Obviously, adding more pages and formats will add development time. This probably wouldn’t be useful enough to be worth it for a normal site, but for my own site, I get to play with whatever cool ideas I want.


Symfony AppCache: built in reverse HTTP proxy

I finally set up my site to work with Symfony’s built in HTTP reverse proxy. Took a little bit of time since I had to fix a couple minor bugs in how things are set up with my symfony-initial and Symfony Standard Edition Bundle and then made a mistake in testing whether or not it was working that made me think it wasn’t when it was.

One useful way to test if it’s working is to set the ‘debug’ option of AppCache to true (turn this back off for production). This will set an X-Symfony-Cache header that will provide info on the cache behaviour. You can see these headers on the shell by running curl -I your.url. If it says ‘fresh’ as part of the header value, that means it was served from the cache. If it shows the header at all, that means AppCache is being used.

For the cache to work, the response must be public and have something set to control how the cache becomes stale. See Symfony’s docs on caching for more details. Since my content rarely changes at the moment, I went with the Cache-Control header with max-age. A cool thing about using Symfony’s reverse proxy is that the entire cache will be cleared when clearing Symfony’s cache like normal. This means that if you make a mistake and must remove it from the cache, there is a quick and easy way.


Toby Now

My roommate has been out of town this week for work. It’s been me and the dogs. I got to work from home a couple days so I could feed them. Normally when I work from “home”, I actually work from the library, because my roommate doesn’t like me working from home. The dogs have been mostly good, though as usual they can be a bit demanding for attention.

Bought myself a few things earlier this week. Got my first ever electric razor (Phillips-Norelco PQ208). I’ve only used it once, but it seems like it’s going to speed up my shaving experience and make it more likely for me to do. Also, since I usually let my blades get rather dull before buying new ones, it will be less painful. It’s just a travel one, so it cost around as much as a 5 pack of blades for my former razor, the Mach 3.

Continue reading post "Toby Now"

House fire down the street

To continue with my fire theme (see Van fire), I was awoken around 0500 to the sound of some yelling and then some fire trucks. I couldn’t see any fire or smoke from my bedroom window, but could see the trucks and firefighters and neighbors outside. I could hear some talking and at one point chopping and breaking glass. There were so many fire trucks with flashing lights that a red glow came through the curtain, reminding me of a certain Seinfeld episode. They took up like half the block parked along the street. One firetruck parked right in front of our house. They were there for a couple hours probably and kept me awake for at least that long (I often have trouble falling asleep). The event got a brief blurb and video on the channel 5 website.


Van fire

On my way home from my brothers, I saw a van on fire. Really on fire. The whole thing was enveloped, the van itself looking like a dark skeleton trapped within. The flames would sometimes jump to at least twice the height of the vehicle or flow across the lane width beside it. Firefighters were around it spraying away. The flames would fluctuate out and in, though always completely covering the van. This was on 480 West.

I witnessed another fire related incident recently as well. I saw a large plume of smoke on my way home from work. I was on 77 North and it looked to be a ways away. I had seen smaller plumes before and had wondered what they were, but never investigated. That day though, I had nowhere to be and was in my car, so I decided to find it. I just drove in its general direction until I got close enough to it. It was on the east side of Cleveland. The traffic around it was terrible and it was really slow going in its vicinity. I didn’t get the best view of it, but I did drive down the roads adjacent to it and saw the huge, rolling, multicolored plume of smoke billowing from pretty close and got brief glimpses of the flames and possibly the building. I saw streams spraying into the smoke and flame. The traffic was bad enough that I got my fill looking at it trying to get out of the traffic jam.


And we’re back

I haven’t posted anything on this site since 2011. My “professional” site and related blog took my attention as I focused on my career. In 2011, this site was hosted from my home on an iBook. That server probably was taken down within a couple years of that post when I moved and didn’t bother trying to get it back up and running. By that point, I had my “professional” site on a shared host (Dreamhost) and liked what it had to offer. I no longer had to worry about keeping my IP updated with DynDNS or the downtime from internet outages (common with my Windstream DSL), server problems, router problems, etc.

This site was down for a period, but at some point I migrated it over to my Dreamhost server. I started it at personal.tobymackenzie.com. After a while, I decided it needed its own domain and would be a good candidate for a .name domain, so I bought tobymackenzie.name. The site was still not fully functional though. Some pages and sections were completely broken, and for a while I couldn’t log into the WordPress install this blog is run with.

Recently, I went through and got most things working and threw a more recent, responsive theme (Twenty Fifteen) onto the blog. A few sections still don’t work. I may have lost the data for the almost never used forums. The gallery is run by software that shared photos from my iPhoto library, no longer possible on shared hosting. I may replace these at some point, though I would probably only put the forum back in a read-only mode for posterity.

Anyway, this site is old and outdated. Some of the information is inaccurate. At some point soon, I intend to replace it with something new, probably something built on Symfony. I hope to merge the code-base and some of the content of my “professional” and personal sites, though in appearance and most content they will remain separate to serve their own purposes most effectively. I will leave this site as is on a sub-domain for posterity. As with most of my personal projects, who knows when I will actually get to it, but I have been itching to play with some things that I don’t get to at work.

As to this blog, I hope to get back into the habit of writing for it. I’ve put a lot of focus on my career lately, but miss thinking and writing about some of my other interests. It can be somewhat therapeutic to write down my ideas or about things happening in my life. Lately, my interest in homes and architecture has been coming back. Hopefully, this blog will be seeing me as regularly as it once did and my thoughts will be archived for my future self and others.


Home Lighting: Sun-light, Moon-light

Every room has sun-light and moon-light. Hallways, stairwells, walkways, etc. probably just have moon-light. The sun-light would be the bright bulb(s) in the middle of the ceiling or by work areas to allow tasks to be performed. The moon-light is the much dimmer, low wattage option like a night-light, for moving about and other less visually precise activities.

Continue reading post "Home Lighting: Sun-light, Moon-light"

</toby>