The Developer Day | Staying Curious

Archive for January 2009

Jan/09

23

Anti Asynchronous AJAX calls and PHP sessions

Few days ago we found a strange bug in one of our applications we are developing. We were creating a certain feature that made up to 2 – 6 asynchronous ajax calls when certain pages were hit. Those ajax requests contact various services providers and it takes a different amount of time for each one of them to respond. We found it odd that none of the calls were actually asynchronous and they were starting to execute one after another. For example we fire 3 asynchronous ajax calls:

  • ajax call 1 takes 2sec.
  • ajax call 2 takes 3 sec. but responds after 5 sec. only
  • ajax call 3 takes 4 sec. but responds after 9 sec. only

It didn’t took long to figure out that it had something to do with our php handler scripts that are accepting these ajax calls. We found out that the session_start() function call did not allow these scrips to run in paralel. It soon became clear that two php scripts can’t use the same session in paralel because without locking they could both do some changes to session and one script would override other script’s changes.

Turns out there is a function for exactly these kinds of situations in PHP and it’s named session_write_close(); It’s purpose is to write session data and end session. After it is done writing it releases the lock for other scripts to use the session. So now our php handler scripts initialize the session to check that the user is logged in, writes the session changes and ends it, contacts services providers and then starts the session again to make the final session changes. That way one script doesn’t hold the session locked for it’s whole execution time.

, , , , Hide

Jan/09

16

FogBugz Time Tracking Reports

We’re using FogBugz 6 for our daily project management needs. It’s a great tool in many ways and I think it will get only better on the way. But FogBugz lacks one quite important feature. There is no way to easily get a report how much time each of your developers spent on their tasks during the day or to see on what are they currently working. You might wonder why is that.

Well it’s quite funny but the company behind FogBugz doesn’t really want to provide this kind of functionality. Because they believe this would make people provide bad estimate data to FogBugz. You can read more about it on Joel on Software blog post about amnesia. They might be true about the bad data thing. But in my opinion they aren’t the ones who should decide how people should to use their tools. If people want to shoot themselves in foot – explain to them that it’s wrong and what will happen if they won’t listen and then let them shoot themselves in the foot.

We for example need to know on what tasks our developers were working during the day and what are they doing at any moment of time. And ofcourse seeing that a certain task took too long or that a developer was doing something without a task for 4 hours is very valuable. In other words if people know for what reason this tracking data is gathered they might as well not lie and provide good data. Don’t force your developers to have 8 hours long reports. You should know they spend atleast 2 hours doing whatever they like.

I tried to look for 3rd party solutions that would in some way allow us to have time tracking reports, but I didn’t like any of them and of course they are all commercial solutions. I got really excited to find out that FogBugz has an API that allows to do various actions. One of those actions allows to get a user time sheet report for a certain time interval. So I quickly developed a small php application that would login to the system with all the users we have and aggregate their time sheets. The application itself is no piece of art but I think it’s simple and it gets the basic job done. You are welcome to try y fogbugz time tracking application out yourself. It has a dependency to ZendFramework’s HTTP client. You can easily replace it with anything you like. To install the application you need to configure the index.php by providing the api url, fogbugz users list, current timezone, and path to the zend framework. If you have any problems or requests please feel free to contact me.

I’m also adding a screenshot if you care how the reports look:

fogbugz time tracking report

, , , Hide

Jan/09

16

Funny MySQL command line option

MySQL has atleast one funny named command line option that made me chuckle. The option is named “–i-am-a-dummy”. From the MySQL manual:

Allow only those UPDATE and DELETE statements that specify which rows to modify by using key values. If you have set this option in an option file, you can override it by using –safe-updates on the command line.

This option is an alias of “–safe-upfates”. I wonder for a while what is the story behind having two alternate names for the same thing. Maybe it’s just the MySQL folks having some fun.

, Hide

Jan/09

8

MySQL – ORDER BY RAND() optimization

Interesting read about order by rand optimization by Jan Kneschke. Haven’t used this myself but seems might be rather useful. The performance difference is huge. I wonder if MySQL could optimize ORDER BY RAND() itself when there are no data holes.

, , , Hide

Jan/09

7

Miško Hevery – Code quality crusade

I found this guy’s blog when i was reading about the singleton issues on planet-php. Someone linked this Miško Hevery and his googletach talk about global state. I have watched all the talks Miško made and I think they are amazing. It’s even more exciting for me because not very long ago we started writing unit tests for our software and we came up with problems and questions we couldn’t answer easily. These talks gave us a better understanding of how we should write our software and unit tests.

The Clean Code Talks – “Unit Testing”

The Clean Code Talks – “Inheritance, Polymorphism, & Testing”

The Clean Code Talks – “Global State and Singletons”

The Clean Code Talks – “Don’t Look For Things!”

Enjoy!

, , , Hide

Find it!

Theme Design by devolux.org