The goal of this code is to create drop-down menu where there are 14 options on the list. Those 14 options are the dates that an RSS feed were last updated. The URLs for the feed have the query
&issue=2014/10/14, but the trick is that it's set so that if a date is entered when the feed wasn't updated, it returns the most recent one instead of an error.
This code finds today's date, goes back one day, builds the URL for the feed for that day, loads that feed and checks if the publication date matches the date in that URL (thereby confirming that the feed was updated that day), and if it's a valid day it builds the option value and adds it to the drop-down list. Then it does that again until there are 14 options.
It also checks whether a day is a weekend first, to skip all the weekend days because I know this feed won't be updated on weekends.
The problem is that if there are big gaps between valid dates, it takes too long to execute and I get a FastCGI timeout error. I'm not interested in lengthening the FastCGI timeout length. What I've done is set the time limit to 2 seconds, which is enough to go through about a month's worth of days and get as many valid days as there are in there.
I feel like this is a really sloppy way to do it but I can't come up with anything better. Hopefully someone with more experience has a better solution!