Checking Mod dates remotely (PHP / ios)

Discussion in 'iOS Programming' started by larswik, Apr 30, 2012.

  1. larswik macrumors 68000

    Sep 8, 2006
    I am looking at improving my app.

    I have an app and it works well testing it. To keep images and information updated on my app, I have the app a couple times a day scan the remote directory and compare modification dates. Example, image1.jpg locally gets compared to image1.jpeg on the remote server. If the dates are different it downloads the new image and replaces the old one. it works very well.

    The problem is it only scan when the app is active and it scans every item maybe 200-300 items. With a good internet connection it takes about 45 seconds. Slow connection many minutes. (I used an UIlabel to display the time elapsed it to from start to finish).

    Can PHP ( I know very little about PHP) scan the directories and create a list of items that have changed day to day? Then the iPhone can down load that list and download only the files that need to be downloaded instead of checking every files mod dates for a change? I am up for any ideas or technologies that I am unaware of that might help speed up this process.

  2. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    The shell has the find command which could be helpful. The following finds files newer than 'lastfilename.jpg' within the folder find is being run it.

    find . -newer "lastfilename.jpg" -type f -name "*.jpg" -maxdepth 1
    So by passing to the server the last file the client previously loaded, you could get a new list specific to the client. With a little parsing you could figure out how to pass back a clean list of file names for the client to fetch.
  3. larswik thread starter macrumors 68000

    Sep 8, 2006
    Ahhh. So in this procedure I would be passing 1 name at a time? if so that would be like checking each file one at a time. Or... Would I pass a list in a txt format or something with all the name and modification dates stored in my app. The server would then parse that list and return a list to the iphone of items it should download if the mod dates are different?

    I will look into that. I know very little about PHP or what it is capable of doing. But I thought I would start to learn it if it can help me refine my search.

    I'll explore your idea and see what I can come up with.

  4. xStep macrumors 68000

    Jan 28, 2003
    Less lost in L.A.
    Actually I don't like my idea anymore. Using the filename is bad because in the case where that filename is updated last later on, a customer could end up missing other files.

    Other thoughts...

    Using a date is a decent way to go. Given a collection of files uploaded to the customer, also pass the most current date of those files. Next time the customer connects, create a list of file names where the date is greater than that saved date which the customer would pass to the server query.

    You could likely use the ls command to sort by newest date first into output that a routine would compare each file date the customer passed to you. Once you get to a date entry not greater than the passed in date, you can stop building the list. Pass the list back and the app could request each image in it.

    To keep life simple, perhaps just generating a static text file with the names and modified dates is a better idea. The app could download that, compare it to the previous version of that file, if it exists, and cherry pick just the filenames with altered dates.

    i mention shell commands because you don't have to use PHP. If PHP doesn't have something similar built in, than you'll end up making a call shell commands anyway.

Share This Page