The goal of this code is to create a drop-down menu where there are 14 options on the list. Those 14 options are the dates that an RSS feed was last updated. The URLs for the feed contain 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!
<?php 
error_reporting(0);
$timer = set_time_limit(2);
echo ("<select id='select1' align=center width=10 onchange='javascript:location.href=this.value;'>");
echo ("<option>-- select past date --</option>");
$i=1;
$j=0;
$pickdate = date("m-d-Y"); //today's date
while ($j <= 13) {
    $pickdate = mktime(0, 0, 0, date("m")  , date("d")-$i, date("Y")); //subtract from today's date
    $new_pickdate = date('D. M. j, Y',$pickdate ); //put date in desired format for dropdown
    $postdate = date('Y/m/j',$pickdate); //put date in desired format for url 
    $xml=("http://[IPremoved]/NewsLetter/postfeed?type=1&issue=".$postdate); 
    $onchangeurl=("http://enews-archive.php?".$postdate);
    $dayofweek = date('N',$pickdate ); //pull day of week
    if ($dayofweek < 6) { //check for weekdays 
        $xmlDoc = new DOMDocument(); //load xml to test if empty
        $xmlDoc->load($xml); //load xml to test if empty
        $channel=$xmlDoc->getElementsByTagName('channel')->item(0); //load xml to test if empty
        $pubdate = $channel->getElementsByTagName('PostDate')->item(0)->childNodes->item(0)->nodeValue; //load xml to test if empty
        $pubdatestamp = strtotime($pubdate);
        $checkdate = date('Y/m/j',$pubdatestamp); //put date in desired format to check
        if ($postdate == $checkdate)  //check if dates match
            {
                echo ('<option value='.$onchangeurl.'>'.$new_pickdate.'</option>'); //if weekday & xml not empty print it
            $j++; //add to counter if it's a valid date
        } //end match check 
    } //end weekday check
    $i++; //increase subtraction from date
} //end while
echo ("</select>");
?>