Re: [PHP] How can i only fetch a (rss/atom) feed when it's changed?
On Wed, 3 Oct 2007, Mark wrote: I'm currently fetching feeds about every hour (automatically in php) but sometimes there are no new updates in a feed for 2 hours. so no i wonder if it's possible to check the feed somehow to see if it changed since i last fetched it and if it's the case than download it like it should.. if it's not changed than just skip the download. Is this possible and how (with filemtime?)? i rather have a method that works in php 4 and 5 (i use php 5 but alot of hosts still don't). If you use a socket request to get the url you get to see the headers along with the file contents. cat fsockopen.php #!/usr/bin/env php ?php $fp = fsockopen( 'destiney.com', 80, $errno, $errstr, 30 ); if( !$fp ) { echo $errstr ($errno)\n; } else { $out = GET /rss HTTP/1.1\r\n; $out .= Host: destiney.com\r\n; $out .= Connection: Close\r\n\r\n; fwrite( $fp, $out ); while( !feof( $fp ) ) echo fgets( $fp, 128 ); fclose( $fp ); } This particular request currently yields this Last-Modified header: Last-Modified: Fri, 21 Sep 2007 12:45:38 GMT This will let you develop a local cache for the rss contents and only update it when the remote file has changed. -- Greg Donald Cyberfusion Consulting http://cyberfusionconsulting.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can i only fetch a (rss/atom) feed when it's changed?
On 10/3/07, Greg Donald [EMAIL PROTECTED] wrote: cat fsockopen.php #!/usr/bin/env php ?php $fp = fsockopen( 'destiney.com', 80, $errno, $errstr, 30 ); if( !$fp ) { echo $errstr ($errno)\n; } else { $out = GET /rss HTTP/1.1\r\n; $out .= Host: destiney.com\r\n; $out .= Connection: Close\r\n\r\n; fwrite( $fp, $out ); while( !feof( $fp ) ) echo fgets( $fp, 128 ); fclose( $fp ); } This particular request currently yields this Last-Modified header: Last-Modified: Fri, 21 Sep 2007 12:45:38 GMT This will let you develop a local cache for the rss contents and only update it when the remote file has changed. i'm not sure that will work. since the feed is dynamically generated, depending on how it is setup it would say it's new all the time, or the modified date would be 1997 or something old to help force a non-caching behavior. could also depend on the script generating the feed... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How can i only fetch a (rss/atom) feed when it's changed?
On 10/2/07, Mark [EMAIL PROTECTED] wrote: I'm currently fetching feeds about every hour (automatically in php) but sometimes there are no new updates in a feed for 2 hours. so no i wonder if it's possible to check the feed somehow to see if it changed since i last fetched it and if it's the case than download it like it should.. if it's not changed than just skip the download. Is this possible and how (with filemtime?)? i rather have a method that works in php 4 and 5 (i use php 5 but alot of hosts still don't). [proper] feeds are generated in real-time. it depends if the server sends along some sort of etag or other modification information, but i would say the nature of RSS is to be dynamic and always up to date. you should just work on something on your end to dupe check/detect new items. that will be a much more consistent solution anyway, since it will work on ANY feed. much better than relying on the server or the other person's code or RSS code generator to tell the right last modification time. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php