Thank you! Your feedback has been delivered
Thank you! Your feedback has been sent

Combine individual XML files into a single XML feed

What I an trying to do is find the ID values of feeds from this XML feed: http://concordiarx.mediaroom.com/api/newsfeed_releases/list.php so that I can use those ID's to generate one file that combines the XML for all the full news releases like this one: http://concordiarx.mediaroom.com/api/newsfeed_releases/get.php?id=122486

Once we have some PHP that gets all the ID's and generates the one single XML with all the news releases, I will then use WP All Import to pull the single XML feed into WordPress. That part I don't have issues with at all, it's super easy.

However, it is also essential that the single XML feed file that is generated is refreshed every 30 mins or so, as I will then need to use the Cron job functionality WP All Import supports to allow for it to then check for updates / new items in the master XML file.

Thank you!!

User Gravatar

creativelogic

Posted Mar 25 2014 12:01 UTC

$100


  • Assigned To avladev
  • Solved
  • php
    wordpress
  • 3771 Views

11 Replies


This is fairly straight forward, just need to know how you want the final XML layout, should it be the same as the full article XML with only articles from ID's that are in the list.php file, or something custom/specific? If you can let me know the format I can finish this for you.

User Gravatar

tripflex

Posted Mar 25 2014 12:27 UTC

Check my solution: https://gist.github.com/avladev/d2e7d994976423ef3dde

Thanks

User Gravatar

avladev

Posted Mar 25 2014 12:56 UTC

Excellent, good to hear this shouldn't be too bad.

  • Yes, same format as a single article should work I think. So it would just be a file with one <release>...</release> after another.
  • And yes, the single XML file will just contain the releases listed in list.php

Thanks!

User Gravatar

creativelogic

Posted Mar 25 2014 12:58 UTC

@tripflex - unfortunately @avladev's answer created single XML files and an "all.xml" file that was the list.php feed but saved locally. This is a good start, but as I mentioned in my second bullet point above, what we need is a single XML file contains the full details of all the releases listed in list.php

If either of you can help from here, that would be great! Thanks in advanced.

User Gravatar

creativelogic

Posted Mar 25 2014 21:47 UTC

My script does just what you asked. Check result.xml file created in current directory this is the result file when combining list.php and get.php results. You can also change $output variable to empty string ($output = '';) to output the file in your browser window.

These files in cache/ folder. all.xml, N.xml are just cached results from concordiarx.mediaroom.com. This cache is used for test purposes to speed up the development. The actual result of the scripts is in result.xml in CWD (or depending on $output setting).

User Gravatar

avladev

Posted Mar 25 2014 22:06 UTC

You can check the result on this URL: http://clients.avladev.name/codersclan/273/

User Gravatar

avladev

Posted Mar 25 2014 22:21 UTC

Sorry @avlavad, you are right, I didn't notice the path for result.xml. Thank you for your work so far, just the last part of my request we need to sort out now...

As noted in your script (which is well documented thank you!) I should set the $cache variable to false in production, which makes sense except then it really slows down whenever I run the script.

This leads to the last part of my initial question. I need to ensure this script only runs every 30 mins or so on this WordPress based website...is the best option for me to just setup a Cron job on my server?

Thanks!

User Gravatar

creativelogic

Posted Mar 25 2014 23:44 UTC

It's slow because of the responses have a little bit delay and also I use $pause_time variable to reduce the load on the server. If the target server is yours you can set $pause_time = 0; this way it will speed up the script with 9 seconds if there are 8 releases.

Please get new version of the script from here: https://gist.github.com/avladev/239809280cf5b2dff0b7 I have a little bug when cache is off and no cache dir exists.

How to move to production:

  1. Put file somewhere on your server for example /home/myuser/scripts/combine.php
  2. Set $cache = false;
  3. Set $output = '/path/to/your/wp-content/releases.xml';

Test the setup: 1. cd /home/myuser/scripts/ 2. php combine.php 3. Then check if the file is generated in http://yoursite.com/wp-content/releases.xml

Create crontab job:

  1. Execute crontab -e
  2. This will open your editor or let you choose which editor to use.
  3. Append this line to end of the file 0,30 * * * * php /home/myuser/scripts/combine.php
  4. Then check next xx:35 minutes if the file is updated.

If you need more information. Thanks

User Gravatar

avladev

Posted Mar 26 2014 0:14 UTC

Solution

This didn't solve your task? Get your own custom solution.

Thanks again @avladev, this was super thorough and worked great.

User Gravatar

creativelogic

Posted Mar 26 2014 15:08 UTC

Thanks Best regards

User Gravatar

avladev

Posted Mar 26 2014 21:34 UTC

What about this solution if we have multiple urls for feed into single xml file.

User Gravatar

user1780

Posted Apr 19 2014 23:55 UTC

Add a reply

By posting a reply on CodersClan you agree to our Terms & Conditions