creating XML with embedded PHP – PHP

  php

Q(Question):

Hi-

I am attempting to set up an RSS feed using PHP. It would be convenient for
me to embed PHP into an xml file like I would do to an HTML file in order to
create the XML, however the apache server does not realize that it’s PHP
content and the PHP engine is not run against that code. so I have to call
it feed.php instead of feed.xml, and most of the rss readers don’t
appreciate this.

My alternative is to create the XML file every day or so (using PHP or
whatever), however that does not guarantee that the person requesting the
rss feed gets up to date info.

I would really like to know if there is a way to create the XML file on the
fly using PHP without modifying the apache server.

Thanks,
troy

A(Answer):

On Mon, 05 Jan 2004 21:54:49 GMT, "Troy" <tr**@morpheus.No_SpAm.net> wrote:

I am attempting to set up an RSS feed using PHP. It would be convenient for
me to embed PHP into an xml file like I would do to an HTML file in order to
create the XML, however the apache server does not realize that it’s PHP
content and the PHP engine is not run against that code. so I have to call
it feed.php instead of feed.xml, and most of the rss readers don’t
appreciate this.

They _shouldn’t_ care so long as you send the appropriate Content-type header
(Content-type: application/xml , I think).
My alternative is to create the XML file every day or so (using PHP or
whatever), however that does not guarantee that the person requesting the
rss feed gets up to date info.

I would really like to know if there is a way to create the XML file on the
fly using PHP without modifying the apache server.

Depends whether you count this as "modifying" the server, but a ForceType
directive in a .htaccess file might do the trick:

http://httpd.apache.org/docs-2.0/mod…html#forcetype

<Files "feed.xml">
ForceType application/x-httpd-php
</files>


Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)

A(Answer):

Try putting a dummy .xml filename into the url.

http://www.somewhere.krakow.pl/feed.php/feed.xml

When Apache fails to find the file /…/feed.php/feed.xml, it’ll run
/…/feed.php instead.

Setting the content-type header should work though. And depending on how
popular the feed is, generating a static version of the file isn’t a bad
idea. You would update the file whenever you add a new story. Since that
should happen less often then retrieval of the feed, it’s more efficient.

Uzytkownik "Troy" <tr**@morpheus.No_SpAm.net> napisal w wiadomosci
news:J2******************@newssvr30.news.prodigy.c om…

Hi-

I am attempting to set up an RSS feed using PHP. It would be convenient
for me to embed PHP into an xml file like I would do to an HTML file in order
to create the XML, however the apache server does not realize that it’s PHP
content and the PHP engine is not run against that code. so I have to
call it feed.php instead of feed.xml, and most of the rss readers don’t
appreciate this.

My alternative is to create the XML file every day or so (using PHP or
whatever), however that does not guarantee that the person requesting the
rss feed gets up to date info.

I would really like to know if there is a way to create the XML file on
the fly using PHP without modifying the apache server.

Thanks,
troy

A(Answer):

"Troy" <tr**@morpheus.No_SpAm.net> schreef in bericht
news:J2******************@newssvr30.news.prodigy.c om…

I am attempting to set up an RSS feed using PHP. It would be convenient
for me to embed PHP into an xml file like I would do to an HTML file in order
to create the XML, however the apache server does not realize that it’s PHP
content and the PHP engine is not run against that code. so I have to
call it feed.php instead of feed.xml, and most of the rss readers don’t
appreciate this.

Is it an idea to keep the script named feed.php, but make the url point to
feed.php?ext=.xml
The script would of course do nothing with the extra variable that is
created with this method, but it might satisfy the RSS readers. I really
wouldn’t know, cuz I know nothing about RSS at all, but it was just an idea
not including server modifications.

Remon.

A(Answer):

Hello,

On 01/05/2004 07:54 PM, Troy wrote:

I am attempting to set up an RSS feed using PHP. It would be convenient for
me to embed PHP into an xml file like I would do to an HTML file in order to
create the XML, however the apache server does not realize that it’s PHP
content and the PHP engine is not run against that code. so I have to call
it feed.php instead of feed.xml, and most of the rss readers don’t
appreciate this.

My alternative is to create the XML file every day or so (using PHP or
whatever), however that does not guarantee that the person requesting the
rss feed gets up to date info.

I would really like to know if there is a way to create the XML file on the
fly using PHP without modifying the apache server.

You may want to try these classes to generate a XML RSS feed:

http://www.phpclasses.org/rsswriter

http://www.phpclasses.org/xmlwriter

Regards,
Manuel Lemos

Free ready to use OOP components written in PHP
http://www.phpclasses.org/

A(Answer):

Chung suggested this and I agree that it makes a lot of sence to update the
XML file only after submission of new stuff.

And depending on how popular the feed is,
generating a static version of the file isn’t a bad
idea. You would update the file whenever you
add a new story. Since that should happen
less often then retrieval of the feed, it’s more efficient.

This works, except in order to create the file in public_html/rss I need to
alter the permissions on feed.xml to 666 since my the webserver user had no
permission to write in my personal user directory. I don’t want to leave it
with 666 perms, so is there another way to do this, or should I let the
webserver user own that file?

Thanks!
troy

A(Answer):

The answer is nope, unless your’re the server administrator.

Uzytkownik "Troy" <tr**@morpheus.No_SpAm.net> napisal w wiadomosci
news:Tl********************@newssvr30.news.prodigy .com…

Chung suggested this and I agree that it makes a lot of sence to update
the XML file only after submission of new stuff.

And depending on how popular the feed is,
generating a static version of the file isn’t a bad
idea. You would update the file whenever you
add a new story. Since that should happen
less often then retrieval of the feed, it’s more efficient.
This works, except in order to create the file in public_html/rss I need

to alter the permissions on feed.xml to 666 since my the webserver user had
no permission to write in my personal user directory. I don’t want to leave
it with 666 perms, so is there another way to do this, or should I let the
webserver user own that file?

Thanks!
troy

LEAVE A COMMENT