You are here:  » Problem with custom RSS feed.

Support Forum



Problem with custom RSS feed.

Submitted by MvdL1979 on Tue, 2016-07-12 18:32 in

Hi all,

I am trying to display the following custom RSS link om my personal website, however I am getting an error:

Warning: file_get_contents(): Filename cannot be empty in /var/www/vhosts/domain.com/domain.com/includes/fetch-feeds.php on line 47

The line #47 is:

file_get_contents(cacheFetch("{link saved}",300));

I also tried the demo, but there was no problem with it... :'(

Any ideas?

Submitted by support on Wed, 2016-07-13 12:52

Hi,

I notice you're using the cacheFetch() function and I see that the error message is "Filename cannot be empty" so this would indicate that the cacheFetch function returned FALSE (fetch operation failed) - the original version would ordinarily return the cache filename but you may be using a later version returning FALSE on error - please could you copy the cacheFetch() function that you're using and i'll check that out for you...

Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Tue, 2016-07-19 17:30

Hi David,

Sorry was feeling sick, so I completely forgot about this thread...

Anyways here it is:

<?php
  
//error_reporting(E_ALL);
  //ini_set('display_errors','on');
  
function cacheFetch($url,$age) {
    
$cacheDir "../cache/";
    
$filename $cacheDir.md5($url);
    
$fetch true;
    if (
file_exists($filename)) {
      
$fetch = (filemtime($filename) < (time()-$age));
    }
    if (
$fetch) {
      
$maxRetry 3;
      do {
        
exec("wget -N -O ".$filename." \"".$url."\"",$output,$error);
        
exec("touch ".$filename);
      } while( 
$error && $maxRetry--);
    }
    if (!
$error) {
      return 
$filename;
    }
    else {
      
unlink($filename);
      return 
false;
    }
  }
  
// {code saved}
?>

Submitted by support on Wed, 2016-07-20 08:41

Hi,

If circumstances have changed on the server it might be best to use PHP's internal URL wrappers via the copy() function, but would also be worth including a check to confirm that the cache folder is writeable - have a go with;

  function cacheFetch($url,$age) {
    $cacheDir = "../cache/";
    if (!is_writable()) die($cacheDir." not writable!");
    $filename = $cacheDir.md5($url);
    $fetch = true;
    if (file_exists($filename)) {
      $fetch = (filemtime($filename) < (time()-$age));
    }
    if ($fetch) {
      $error = copy($url,$filename);
    }
    if (!$error) {
      return $filename;
    }
    else {
      unlink($filename);
      return false;
    }
  }

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Wed, 2016-07-20 14:18

Hi David,

Thanks for answering.

The cache folder is writable, because all my other feeds are working without issues. :)
So I doubt that is the issue.

I think it's one of the new feeds has some weird search strings in it?

[quote]
file_get_contents(cacheFetch("{link saved}",300));
[/quote]

I think that's causing issues...

Regards

Submitted by support on Wed, 2016-07-20 14:26

Hi,

Ah - if the problem is feed dependent then yes, characters in the URL could cause problems with the shell out to wget in the cacheFetch() function. The addition of escapeshellarg() around the URL should do the trick - in your existing code, locate this line;

  exec("wget -N -O ".$filename." \"".$url."\"",$output,$error);

...and REPLACE with:

  exec("wget -N -O ".$filename." \"".escapeshellarg($url)."\"",$output,$error);

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Fri, 2016-07-22 07:05

Hi David,

Well I replaced (in fetch-feeds.php) the following:

  exec("wget -N -O ".$filename." \"".$url."\"",$output,$error);

With:

  exec("wget -N -O ".$filename." \"".escapeshellarg($url)."\"",$output,$error);

And ran fetch-feeds.php. No errors popped up (online and/or in the logs), however all feeds are empty now!

So I put the original line back. And now it's working again... :|

Submitted by support on Fri, 2016-07-22 08:44

Hi,

I think replacement should actually have been;

  exec("wget -N -O ".$filename." ".escapeshellarg($url),$output,$error);

...however if all working fine now it may just have been a transient network error affecting that particular feed. Any further problems at all just let me know of course;

Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Mon, 2016-07-25 08:50

Hi David,

Sorry for the confusion, but I meant I replaced my original code back in so I got the other feeds, the other one still didn't work.

But I tried the corrected code and it seems to be fetching feeds, though due to my own mistake, I uploaded my old fetch-feeds.php which doesn't have the new feed in it which caused the problems in the first place. I have to try this when I get back home (where I have the correct fetch-feeds.php with the problematic feed).

But I think the correct code will fix any issue's though. Will report back when I get back home and try this (if I don't forget). :)

Sorry for the confusion once again though.

Submitted by support on Mon, 2016-07-25 11:39

No problem!

Let me know if you're still not sure of course;

Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Tue, 2016-07-26 17:17

Hi David,

Well still the same issue unfortunately, even with the new code... :(

I re-entered the line with the feed:

<?php
file_get_contents
(cacheFetch("{link saved}",300));
?>

And when I run fetch-feeds.php manually I get: Warning: file_get_contents(): Filename cannot be empty in {code-saved}/fetch-feeds.php on line 49

Line 49 is the one above from fetch-feeds.php.

It's really weird though, because it works in your demo. :|
I am guessing it's because of all the characters which are used in there, because all other / older feeds are working without issues.

I had to switch to this one, because VCDQ died as a feed source. :(

Regards

Submitted by support on Wed, 2016-07-27 08:00

Hi,

It looks like the feed requires a user-agent to be set so this can be added to the exec line in your cacheFetch() function - have a go with:

  exec("wget --user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0" -N -O ".$filename." \"".$url."\"",$output,$error);

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Tue, 2016-08-02 06:35

Hi David,

Just a follow-up. I tested it a few days and it seems to be working. TY! :)

I did notice something else. Probably not related to Magicparser, but not sure.

I use Magicparser mainly for my personal starting page. It has mainly news (local news, abroad news and sport news and some hardware and movies feeds). Everything works, however I am experiencing something really annoying.

For some reason, it always displays old, or better said 'previous', feeds. This happens even if I open a new windows with my starting page. I have to hit F5 before it actually refreshes the contents. I don't know what's causing it and I only noticed it recently.

I already tried adding:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />

So it shouldn't cache the website, however it will still do so...?

Any ideas or experienced this before?
...I am pretty clueless what is causing it.

Regards,
Michel

Submitted by MvdL1979 on Tue, 2016-08-02 06:39

I took 2 screenshots as well of the sports section.

This is what I have when I open my browser (and it loads my starting page), the same goes for when opening a new tab (which also opens my starting page): {link saved}

If I hit F5 then the contents gets updates: {link saved}

It's really strange / weird... :|

Submitted by MvdL1979 on Tue, 2016-08-02 06:40

Oh and more thing; it's not just Firefox, it happens with every browser. It always displays older / previous feeds (contents). Until I hit F5.

Submitted by support on Tue, 2016-08-02 07:21

Hello Michel,

This is my usual anti-cacheing code block - use right at the very top of the script - it must come before any content has been generated by the script;

<?php
  header
('Cache-Control: no-cache, private, must-revalidate, max-stale=0, post-check=0, pre-check=0, no-store');
  
header('Pragma: no-cache');
  
header('Expires: Thu, 1 Jan 1970 00:00:00 GMT');
?>

Hope this helps!
Cheers,
David
--
MagicParser.com

Submitted by MvdL1979 on Tue, 2016-08-02 08:54

Awesome! Thanks David!

Never noticed this "issue" before to be honest! :S