Rebooting rssCloud

I recently built an rssCloud Server implementation in node.js

It’s open source, MIT licensed and available on GitHub. I have a copy of it running live at I’m hoping to get folks to poke it and help me make it more stable.

Since it’s hard to test an rssCloud server without data flowing through it I also built a Hacker News Firehose Feed which is populated live using the Hacker News API. It’s also open source, MIT licensed and available on GitHub.

Please submit issues on GitHub and I’m open to pull requests.

Will this make me feel better tomorrow?

I came home for lunch today and I feel like crap. I feel stressed and tired most of the time.

I shouldn’t though. Since the end of December I’ve been doing yoga 2-3 times a week. Even though I have an 8-month old daughter I actually sleep pretty well. My job does stress me out pretty regularly, but it’s way better than it was back in August. I have two great developers on my team now that I’m able to have work on things so I don’t have to.

However I don’t eat particularly well. My wife and I are trying to improve, but it’s difficult. I don’t typically plan my meals in advance which puts me in situations where I’m hungry and I need to find something to eat. That usually means I end up going out to eat or eating something quick at home that may not be ideal for being healthy.

So today I had an idea. Before I eat something, I need to ask myself a simple question.

Will this make me feel better tomorrow?

This doesn’t have to only apply to food. Just something in general I should be more aware of. I think too much of my daily habits are less than ideal, and happen because I’m trying to solve a short term problem. How do I make myself feel better now? What can I eat now?

Yes, I do need to start planning my food out more, but hopefully this minor change will help me make better decisions in the short term.

Facebook Comments

Dave Winer uses Facebook comments on his Liveblog and today I wanted to comment on his post about liveblogging. However before I did this I had to check something out.

I went on Facebook and found where he had posted a link to his post and was surprised to find one comment on Facebook and zero comments on his post.

Why doesn’t Facebook keep these in sync? I would think it would be way better for Facebook and for bloggers if comments on one page showed up on the other. Why split the conversation?

Laravel UTC Model

I’ve been playing around with Laravel lately and overall I like it.

One issue I ran into pretty quickly was that I would like to store datetime fields in the database as UTC and then store the timezone (in this case for an event) in another field.

Laravel seems to have a global timezone configured and any DateTime pulled out of the database is assumed to be this timezone. If you assign a field with a different timezone it doesn’t seem to convert to this global timezone when saving so you can end up with weird inconsistant timezones all over the place.

So I put together a little class that extends IlluminateDatabaseEloquentModel and converts between timezones on the fly.

It also allows me to specify the timezone I want to use (defaults to app.timezone) for that particular model.

If you’re a Laravel developer I’d love to get some feedback as I’m new to Laravel and I may just be missing something.

Here’s the code: UtcModel.php

PHP 5.5 vs HHVM

At my job at Pinpoint Software, I’ve been working on our primary product Taskle. It’s been very successful so far and we’re adding a bunch of new companies to our system all the time. Of course that means scaling issues.

The current issue is that the cron job that marks expired tasks as incomplete and schedules new tasks has a disproportionate number of tasks that start and end at midnight. Most of our customers right now are in Central or Eastern timezones so all daily tasks end and start at midnight. So at this time I see our server CPU levels spike and a cron job that normally takes seconds to finish, takes over two hours to run. This is only going to get worse as we add more customers.

There are two ways I see to scale this. The first is to just break the code up so I can run multiple servers in parallel so the whole thing gets done quicker. This will have to be done sooner or later and I’m actually in the middle of tweaking the code to make this possible.

The second way is to make the cron job run faster with a smaller CPU footprint. This is also ideal as it will mean fewer parallel servers.

Perhaps PHP isn’t the best tool for the job, but I don’t have the time, skill or resources to rewrite it in another language like Java or C. It is possible I could find the bottlenecks and rewrite them as a PHP extension, but I’ve never done that before and I’m not certain of my abilities in doing that.

So as a first step I thought “What about HHVM?”. If you’re not familiar, HHVM is a virtual machine written by Facebook to essentially compile PHP into bytecode and run faster with less memory and a smaller CPU footprint. This would be ideal because I could just use my existing code and get an instant performance boost.

But HHVM isn’t exactly PHP and although they are working to make it as compatible as possible, there could be weird edge cases. So what do I do? Let’s run our unit tests through HHVM and see if they pass. Yes! They do all pass, however I saw something weird when I did this.

Running my tests with HHVM took 23 times longer and 1.8 times more memory.

I’m guessing that this is because it takes longer to compile everything and that the real benefits will be seen in running my normal code. One of my next tests will be to run a long cron job with PHP and HHVM and see which is quicker and maybe see the best way to measure memory and CPU usage.

If you have any experience with this sort of thing I’d be very interested in learning more about how to do it.

I did some googling and found the post Go Faster! on the HHVM blog, but it seems out of date. Since then they moved config to ini files which I was able to figure out but I can’t for the life of me get the pre-analyzing to work.

It seems like HHVM should be caching the compiled files, but even if I run my tests multiple times I don’t see any performance bump.

Running River4 with forever

I’ve been playing around with Node.js for a while but I never got far enough to deploy an app to production.

Dave Winer recently released River4 which is the latest in a line of excelent River of News aggregators.

Previous versions ran on the OPML Editor which I’ve been having a harder and harder time keeping alive. So I was very happy to see River4 was a Node.js app.

The only issue is that step 4 of his instructions says:

Launch river4.js on a node.js system.

If you’ve never done this before it’s somewhat vexing. Dave has some links to resources about Heroku, but I have a Linux server sitting in my basement that I wanted to use, so how should I keep the app running as a long term service?

After some digging I found the glorious app forever which is “A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).”

Installing and using it was very easy. After following steps 1-3 from the River4 repo I ran:

This will launch River4 as a background process, keep an eye on it and restart it if it crashes. Then I finished the rest of the steps 5-8.

When Dave releases an updated version it’s simple to upgrade:

I currently have 5 rivers running but my main one is

Figuring out Silex SecurityServiceProvider

I’m working on a couple of projects that will be using Silex as the underlying framework.

Whenever I try out a new framework, it seems that the first roadblock I always hit is when I try to implement user authentication & authorization. It’s no different with Silex.

The recommended way is to leverage the SecurityServiceProvider which provides a mechanism to handle a lot of the behind the scenes like properly encoding passwords and defining the permission structure of your website without your controllers needing to know much about your security.

It seems very flexible, but it also seems like a pain in the ass.

What I want to do is have an authentication token available everywhere on the site so I can check to see if the user is logged in or not and change links in the header and whatnot. There are public parts of the site where anonymous users (not logged in) can visit. There are also sections that are off limits to everybody but admins.

This is the configuration I ended up with that seems to work for me. I’ll explain after the snippet.

Things to note.

  1. The entire site is included in the firewall but anonymous is set to true.
    • This means anonymous users are allowed
    • Everything is accessible by default to everybody
  2. The automatically generated routes are not admin_logout and such as you’d see in the docs. They are created based on the path. So for me the logout route is user_logout.
  3. You then define $app['security.access_rules'] to specify what sections are actually protected.
  4. UserAuthUserProvider is specific to my project and it implements Symfony\Component\Security\Core\User\UserProviderInterface

This took a fair amount of dicking around to get working for me. Hopefully this post will decrease the amount of time you have to spend dicking around. 🙂

The future of PHP (and JavaScript)

As a developer, I’m always reevaluating what tools I use to do my work. This can be what language I’m using, but also what frameworks, libraries or editors I’m using.

I’ve been doing pretty much nothing but PHP for close to a decade and I love it. I know it’s cool to dis PHP and talk about how awful it is, but honestly I think it’s a great tool for what it’s designed for. Recently I’ve been learning Node.js. Partly because it’s fun, but also because I see JavaScript as the biggest threat to PHP.

Now don’t get me wrong, I don’t think JavaScript is going to kill PHP (nothing ever dies) and I don’t think Node.js will eclipse PHP in popularity anywhere in the near future. But the trend I see is that new applications are being built primarily in client side JavaScript and the back end is little more then an API. That API can be built in PHP, Ruby, Python, whatever. It’s only logical to determine that if this trend continues, we’ll end up with a lot of skilled JavaScript developers who don’t want to write their APIs in a different language. That’s where Node.js comes in.

Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

If you look up PHP on Google Trends it doesn’t look pretty. It’s “web search interest” has steadily decreased since 2004 (the earliest data you get in Google Trends). However I think this is a red herring. PHP is such an elephpant in the room (har har) that it’s not enough to be a PHP developer these days, you have to specialize. We have WordPress, Yii, CodeIgniter, Symfony, Drupal and about a million other frameworks and applications that are built in PHP, each have become ecosystems of their own.

WordPress which now powers 18.9% of the web has shown a steady increase on Google Trends. Then if you compare some of the popular PHP Frameworks the jury is still out on a clear victor.

Remember that chart of PHP on Google Trends? Well take a look at JavaScript on Google Trends. The line is pretty much parallel with PHP and I don’t think anyone is suggesting that JavaScript is dying. JavaScript is showing a downward slope because people are no longer searching for JavaScript, they are searching for jQuery and Backbone.js.

I feel very secure in my career as a PHP developer and I don’t think I’ll be porting Date Check Pro to Node.js anytime soon. Have fun doing what you do. If you’re a PHP developer try out a new framework or even give Node.js a try. It certainly won’t hurt to become better at JavaScript.

Triggering Safari Reader

I do most of my blog reading on my iPhone so it’s really important for me that
my blog looks good on the iPhone.

One feature that I really like is the “Reader” feature that shows up in the
address bar on both mobile and desktop Safari.

One issue with it though is that there is no documentation (that I can find)
about how to markup your site so it consistently triggers the reader.

I noticed that on some of my shorter posts it didn’t work and in reality it’s
not that big of a deal because my site is responsive, but it still bugged me.

After digging through blog posts, comments and forums I came across this comment
that showed that one word of content in an html5 article tag with a height of
350px triggered the reader.

So I started doing some testing of my own. What I found is that in desktop
safari I was able to wrap my content in an article tag and set min-height to
350px and short content would trigger reader. If I shrunk the width of the
browser to a phone width and refreshed the page it did not trigger. If I
increased the min-height to 450px then it worked, but when I published the
site live and tested on my phone it did not work. I had to increase min-height
to 600px in order for my iPhone to show reader on a short blog post.

This is a pain in the ass, especially since the reader isn’t respecting the
constraints of the article tag. It also pulls in the “Feedback” section in
the footer of each blog post. Not the end of the world but still annoying.

I’m guessing part of the reason it’s kept a secret is that Apple doesn’t want
sites messing with it and hiding the post content and showing ads instead (or
something along those lines). People were certainly getting upset when this
feature was released.

Improving My Code

I’ll be honest with you. I had kinda stagnated over the last couple years when it came to improving my skills as a developer. When I first started developing professionally I went from not knowing much PHP to being well regarded as a developer in a few years.

Part of my improvement came from building content management system after content management system for about the first 3.5 years. Lots of iteration and certainly a few big mistakes.

But then I hit my stride. I was writing good code and there was no real external pressure to improve. Things are different now.

I don’t have any external pressure in the form of people telling me I have to get better. It’s more external pressure of supporting code I wrote 2 years ago and finding all the areas that really need to be improved.

One thing that really illustrated to me that I was not developing code as well as I could be was the video Architecture the Lost Years by Robert Martin and then reading his book Clean Code.

My app was built on Kohana 3.1 which is a nice framework, but was not really built on a test driven development methodology. There are a lot of static methods. Take a look at this database example and see what’s typical.

I was thinking that the solution would be to build an API on Symfony and then rewrite the site to just be a front-end calling API methods. This may still be the final solution, but I think first I need to reorganize and clean up the existing site. There are certainly ways (as illustrated in the Robert Martin video) to write well tested code that is outside of your framework and you use the framework as a delivery mechanism. Once I do this, I could theoretically take the code I’d written and move it from Kohana into Symfony if that makes sense and I won’t have to reinvent the wheel.

We do a lot of complex SQL queries so it’s about time to get off the ORM so I can fine tune and optimize my queries and database tables.

I’m learning stop myself and ask “Is what I’m proposing actually the best idea?” and “What other things could I do to solve this problem?”. If I force myself to come up with a few possible solutions I’ll probably find that my first solution was not optimal.