简体   繁体   中英

Getting Wordpress RSS feed without making a HTTP request

I'm trying to get my blog's RSS feed and manipulate it in PHP. Accord to the documentation , the XML feed for all Wordpress blogs can be downloaded at this address:

http://www.example.com/feed/atom/

I've written some simple code that works fine on a test server, but won't work on my hosted server:

$feedUrl = 'http://www.example.com/blog/feed/atom/';
$rawFeed = file_get_contents($feedUrl);
$feedXML = new SimpleXmlElement($rawFeed);

The reason for this is because my hosting provider prevents scripts making HTTP (port 80) connections back to the same server that they're running on.

How can I get access to the feed without needing to do a HTTP request to the same server?

I have tried accessing the URL directly (ie /home/example.com/blog/feed/atom), but nothing is found because it needs a proper request to generate the XML RSS feed. I've also tried a CURL request, but I got the same result.

It's a tricky problem! Thanks for any help!

Note: My solution needs to run on a non-WP page.

Some hosting providers might let you set up CRON jobs through their admin console, without having access to the command line. In a situation like that, you may be able to use a WP-CLI command to retrieve the output of the feeds, and save it to a file using something like "> filename.txt" at the end of the command.

See here: http://wp-cli.org/ And possibly here: http://wp-cli.org/commands/eval-file/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM