I currently have a very simple news system that reads in RSS from a local file using DOMDocument->load(). In addition there is a very simple back end that adds items to the loaded feed and saves it back using DOMDocument->save().
This works fine on my testing server, but when deployed to the client the save operation fails with a 500 error. I think this is due to limitations they have in place which also prevent use of fopen and file_get_contents, although I’m confused by how I can load the XML fine, but not save it back again.
So really I have two questions (naughty, I know):
- Does DOMDocument’s save method differ substantially from load, and what is the underlying technique used to write the file?
- How would I go about saving a DOMDocument object as XML using cURL (because I know cURL is permitted)?
For what it’s worth, here is a truncated version of the load/save:
//load the xml
$doc = new DOMDocument();
$doc->load($_SERVER['DOCUMENT_ROOT'].'/news_rss.xml');
$doc->formatOutput = true;
//add some stuff to the xml ...
//save it again
$doc->save($_SERVER['DOCUMENT_ROOT'].'/news_rss.xml');
curl and dom don’t have much to do with each other. Curl just fetches a specified resource (or sends data to a resource). DOM parses xml/html trees. The fact that you can point dom at a particular URL and get that url’s contents is a byproduct of PHP’s file-based functions allowing URLs.
There’s no link between DOM and CURL, so you can’t have DOM invoke curl to fetch/save for you. You’d have to use CURL to fetch some resource and save it into a temporary file (or a variable), then use that file/variable as a source in DOM. The same goes vice version – DOM cannot invoke curl to save a file.
Given that your load/save calls aren’t using URLs (just a local file path), I’d check permissions on the news_rss.xml file. Generally most files on a system are readable by everyone, but not everyone has write permissions.