SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Find a way to update rss for custom

    I am design a website, witch could allow custom to give rss from search result. To avoid a large query, the best way may be create static .xml files. Then according the xml create date, do an automatic update per 24 hours.

    I think the better way is use php to make a judge, if time()-filectime>24*60*60, do a .xml update, else just read the old .xml file. But, how to do this judge? custom will read the .xml directly, and xml can not make a `time()-filectime`

    Or any better way to suggest me? Many thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    67
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Would this not work?

    PHP Code:
    $filename 'path/and_name_of_the_file.xml';
    if(
    file_exists($filename) && filectime($filename)+(24*60*60) > time()){
        
    // show the old xml file
    } else {
        
    // modify the xml file and show it


  3. #3
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, maybe this is a better method.

  4. #4
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, to show the xml file which one is faster? include($filename) or get_file_contents($filename) ?

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    67
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cj333 View Post
    By the way, to show the xml file which one is faster? include($filename) or get_file_contents($filename) ?
    I would use file_get_contents() because then you can still manipulate the file contents like so:

    PHP Code:
    $filename 'path/and_name_of_the_file.xml'
    if(
    file_exists($filename) && filectime($filename)+(24*60*60) > time()){ 
        
    $contents file_get_contents($filename);
        
    // do stuff with contents if you need
        
    echo $contents;
    } else { 
        
    // modify the xml file and show it 


  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2011
    Posts
    67
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ofcourse you could also use include() and a buffer.

    PHP Code:
    $filename 'path/and_name_of_the_file.xml'
    if(
    file_exists($filename) && filectime($filename)+(24*60*60) > time()){ 
        
    ob_start();
        include(
    $filename);
        
    $contents ob_get_contents();
        
    ob_end_clean();
        
    // do stuff with the contents if you need
        
    echo $contents;
    } else { 
        
    // modify the xml file and show it 


  7. #7
    SitePoint Member
    Join Date
    Jan 2011
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I think I also will choose file_get_contents(), thanks again


Bookmarks

Posting Permissions

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