Results 1 to 5 of 5
  1. #1
    Newbie
    Join Date
    February 8th, 2008
    Posts
    10
    Tell When Datafeed Was Last Updated
    As I'm sure we've all come across, I have a multi-feed sourced website that uses records from up to 17 different merchants stocking similar products. The problem... while some of the merchants are excellent at keeping up to date with the updates ie. in and out of stock products, some are woeful!

    This puts my site in jepordy displaying some very inaccurate info. I've tried to reason with the merchants and it's not their priority - however I don't want to lose their listings on my site either... the ones that ARE in stock.

    I need to find a way of, while running my own update script, being able to tell if a feed has changed from the previous time I ran it. I have asked my affiliate host to see if there's a way of having a timestamp imprinted on the file that I can use as a variable against today's date to see if it's beyond a certain period (say 5 days) to simply mark all of that merchant's products as out of stock until it is updated again.

    They've responded by saying they will look into this, but it will take an eternity i'm sure.

    is there a php script or way for me to check if a datafeed has changed since the last time i ran it and calculate how long since?

    yours hopefully,

  2. #2
    Newbie
    Join Date
    May 15th, 2008
    Location
    Flowery Branch, Georgia
    Posts
    7
    The following code is something I use. I only want to download datafeeds that are newer than the ones I've downloaded before else I skip them.

    "********** $filedate = date of datafeed file
    ********** $serverfile = file on your server

    $filedate = date("Yz", ftp_mdtm($conn,$dirarr));
    $serverfile = "download/".$dirarr;

    ******** If you've downloaded the file previously, get the date you downloaded else set date to 00000
    if (file_exists($serverfile))
    {
    $servfiledate = date("Yz", filemtime($serverfile));
    }
    else
    {
    $servfiledate = 00000;
    }

    ******** if datafeed file date is newer than your previously dowmloaded file, download it
    if($filedate > $servfiledate)
    {
    ftp_get($conn,"download/".$dirarr,$dirarr,FTP_ASCII);
    }

    ********* download is the directory I download my datafeed files to.
    "

    Hopes this helps,
    Danny

  3. #3
    Newbie
    Join Date
    February 8th, 2008
    Posts
    10
    that is exactly what i need. one question though... i read the data from my feed in a slightly different way and i'm not quite sure how to... jig this code around to suit me.

    Code:
    $xml = simplexml_load_file('**********************');
    
    foreach ($xml->xpath('//merch') as $character) { etc. etc. }
    i'm not the most adept at trial and error. any guidance to steer me in the right direction?

  4. #4
    Newbie
    Join Date
    May 15th, 2008
    Location
    Flowery Branch, Georgia
    Posts
    7
    Not sure what you're asking here.
    The date check would come before the simpleXML load file.
    In fact, the load file within the if statement of the data check.
    As I understand it, simpleXML allows your read your file so you have already found the file you want to read, correct?

  5. #5
    Newbie
    Join Date
    May 15th, 2008
    Location
    Flowery Branch, Georgia
    Posts
    7
    Halifaxer,

    I just realized the date compare does not work when comparing today's date with a date from last year. The reason is because the format of today's date is only 6 characters (200911) while comparing to a file from last year could be 7 characters (2008365).
    To correct this, copy the following code immediately after you get the file date:

    if (strlen($filedate) == '5')
    {
    $filedate = substr($filedate,0,4)."00".substr($filedate,4,1);
    }
    if (strlen($filedate) == '6')
    {
    $filedate = substr($filedate,0,4)."0".substr($filedate,4,2);
    }

    You'll need to do this for both files you want to compare to insure both lengths are equal.

    I found this out today when trying to run my FTP and no files were downloaded.
    After making this change, my files started downloading.

    Danny

  6. Newsletter Signup

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •