Click to See Complete Forum and Search --> : RSS Create Script Errors


Shmohel
04-25-2006, 07:55 AM
I have a real simple scirpt to put together an RSS file for me. It was working perfectly, and then all of a sudden a I started getting the below error:


Warning: fopen(xml/rss1.xml): failed to open stream: Permission denied in /home/shmohel/public_html/rss.php on line 2

Warning: fwrite(): supplied argument is not a valid stream resource in /home/shmohel/public_html/rss.php on line 23

Warning: fclose(): supplied argument is not a valid stream resource in /home/shmohel/public_html/rss.php on line 24

Here is the entirety of the script, only about 25 lines:

<?php
$file= fopen("xml/rss1.xml", "w"); #This is line 2
$rss.='<?xml version="1.0" encoding="ISO-8859-1"?>';
$rss.="<rss version='2.0'>";
$rss.="<channel>";
$rss.="<title>10 Newest Recipes - Recipe Tavern</title>";
$rss.="<description>A list of the 10 most recently submitted recipes at the Recipe Tavern.</description>";
$rss.="<link>http://www.recipetavern.com</link>";
mysql_connect ("localhost", "*****", "*****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("*****");
mysql_select_db ("*****");
$sql=mysql_query("SELECT r.recipeid,r.recipename,r.desc FROM *****.`recipe` AS r JOIN *****.`beer_members` AS m ON r.memberid=m.id ORDER BY dateadded desc LIMIT 10;") or die(mysql_error());
while($rec=mysql_fetch_assoc($sql)){
$rss.="<item>";
$rss.="<title>".$rec['recipename']."</title>";
$rss.="<description><![CDATA[".$rec['desc']."]]></description>";
$rss.="<link><![CDATA[http://www.recipetavern.com/index.php?pg=recipe&recipeid=".$rec['recipeid']."]]></link>";
$rss.="<guid isPermaLink='false'>recipetavern_recipeid_".$rec['recipeid']."</guid>";
$rss.="</item>";
}
$rss.="</channel>";
$rss.="</rss>";
fwrite($file, $rss); #This is line 23
fclose($file); #This is line 24
?>

So, the problem seems to be with getting the script to open. I thought it might be a permissioning issue. (By the way, what permission do you think I should have the XML file set to?) But, playing with that did not solve it.

Any other ideas why this all of a sudden stopped working?

chazzy
04-25-2006, 08:25 AM
Warning: fopen(xml/rss1.xml): failed to open stream: Permission denied in /home/shmohel/public_html/rss.php on line 2

Seems that the permissions changed on the file changed.

rch10007
04-25-2006, 08:35 AM
Can someone explain why the <![CDATA[ tags are necessary?

Shmohel
04-25-2006, 08:47 AM
Can someone explain why the <![CDATA[ tags are necessary?

Can't give you exact specifics. I just know it was not loading properly without them. Basically, the tag tells the browser that the data contained is simply that, data, and not supposed to be read as containing any script. Someone else here would better be able to explain if I am right.

Shmohel
04-25-2006, 08:48 AM
Seems that the permissions changed on the file changed.

I have changed the permissions around, and can't seem to get the script to run. Any idea what they should be? At first they were on 644, then I kept changing around, to 755 and eventually jsut to 777 to see if that would fix.

NogDog
04-25-2006, 09:26 AM
Can someone explain why the <![CDATA[ tags are necessary?
They are used to delineate a section of character data that might include characters which would otherwise be confused as markup characters.

http://www.w3.org/TR/2000/REC-xml-20001006#dt-cdsection

rch10007
04-25-2006, 09:32 AM
Ah, ok! I have seen RSS markups using them and some that didn't. All I know is that when I was making my feed script, I had to strip those to get to the content.

thx!

chazzy
04-25-2006, 11:00 AM
I have changed the permissions around, and can't seem to get the script to run. Any idea what they should be? At first they were on 644, then I kept changing around, to 755 and eventually jsut to 777 to see if that would fix.

So right now they're at 777 and they won't run? Has anything changed on this server? I'm assuming this is a shared environment, right? My thoughts are to go back to your host, they might have changed something or other.

Shmohel
04-25-2006, 04:14 PM
You'd think that was the answer, but I have been back and forth with them on this and so many other issues. They keep assuring me nothing has changed.

So, I am not nuts? There doesn't appear to be any blatant mistakes in my code? I will send this to my host and see if they can explain it. Here goes nothing.

chazzy
04-25-2006, 05:02 PM
You'd think that was the answer, but I have been back and forth with them on this and so many other issues. They keep assuring me nothing has changed.

So, I am not nuts? There doesn't appear to be any blatant mistakes in my code? I will send this to my host and see if they can explain it. Here goes nothing.


Never said there was nothing wrong. But if you're saying that the fopen used to work, now it doesn't, then there has to be a permissions issue somewhere.

As for your code...


<?php
$file= fopen("xml/rss1.xml", "w"); #This is line 2
$rss.='<?xml version="1.0" encoding="ISO-8859-1"?>';


How can you add something to $rss during its first use? You should have a .= on this line, but an = only. Also, just as a tip, you shouldn't even begin writing or opening the file if you can't get a database connection. So maybe open the file, open the db, then write it.

NogDog
04-25-2006, 05:58 PM
Do you have write permission on the xml directory, too?

NogDog
04-25-2006, 06:01 PM
Oh, by the way, .= works just fine to make an initial assignment to a variable, though it makes the code a bit less readable (since the reader will tend to assume the variable must already have had an initial value assigned to it).

chazzy
04-25-2006, 06:42 PM
Oh, by the way, .= works just fine to make an initial assignment to a variable, though it makes the code a bit less readable (since the reader will tend to assume the variable must already have had an initial value assigned to it).

actually, it usually throws a notice about the variable not being declared before hand. may differ from version to version.

NogDog
04-25-2006, 07:19 PM
actually, it usually throws a notice about the variable not being declared before hand. may differ from version to version.
Good point. I'd seen it used in some script that I ended up trying on my hosting service, where the error reporting level is higher, and it didn't complain; but it does throw a notice on my local PC installation (where I have error reporting at E_ALL).

Shmohel
04-26-2006, 08:21 AM
Thanks for the tip. I was under the impression it didn't make much of a difference lik NogDog first mentioned.

As for the directory, it is set to 777 as well, and I have several other scripts that seem to create XML documents in that folder just fine.

Wow... am I a moron. I just realized every time I have been chmod the permissions on the file to 777, it never accepted it. FOr whatever reason it kept setting it to 644. So, I deleted the file, ran it and allowed the script to recreate the file. And changed the permissions, and it works now.

I wonder what could have caused it to not allow me to change the permissionson that one file.

NogDog
04-26-2006, 08:30 AM
Were you doing the chmod via the PHP chmod command? If so, it probably didn't work because the script was not executed by the file owner (it gets executed by a user named "nobody", or "www", or some other name depending on your web server setup.)

Shmohel
04-27-2006, 09:56 AM
No, I was doing it through my FTP program (which has been acting screwey lately, but that is a WHOLE other topic.) Thanks.