Hi All,
New Member, First Post…Sorry it’s so long.
Some background; I have a little experience (emphasis on little) with building static websites but the need has arisen to dive into creating a dynamic website serving information from a database. To that end, I have decided on the Linux /Apache / MySQL/ PHP route and have been studying “Build Your Own Database Driven Web Site Using PHP & MySQL, 4th Edition” by Kevin Yank, as well as everything I can find on the web. I’m getting the display of the relevant data sorted out, but I’m stuck on how to get the data into the database. (not from forms, that makes sense);
We need to monitor logging equipment in the field which periodically sends in data via a server run by the equipment manufacturer. The vendors server needs to send data to our server via an XML message via HTTP POST.
Following is a excerpt of the vendors documentation:
The basic format of the HTTP POST is defined below: (note that the Request-URI,
Hostname, and Content-Length will change based on destination and message.)
Syntax: Send Messages
HTTP Method: POST
Function: Send a batch of data modem messages to a destination.
Response Format: XML
Request:
POST <DestinationName-Request-URI> HTTP/1.1
Host <DestinationName-hostname>
Accept: text/xml
Content-Type: text/xml
Content-Length: 123xxx
<?xml version=”1.0” encoding = “UTF-8”?>
<messages>
………
</messages>
I need to parse the data contained in the XML /messages section and place into the appropriate tables.
I’m not looking for details yet, just the big picture, can I deal with this completely in PHP? Is there a better way?
Is this handled the same as a page request coming from a browser? (ie: point the vendors at a directory with index.PHP that accepts the request? I’ve looked at the built in PHP XML functions, but not sure that’s what I’m after.
Thanks,
I had looked at the simplexml documentation, and I think I understand its use. What I’m confused about is getting the xml file/data to work on;
The documentation for the simplexml functions seem to show how to manipulate xml contained in a file. I’m trying to understand how to receive the xml data as part of a HTTP connection from a client server, based on the documentation in my original post. Everything I’ve studied is from the point of view of interacting with a browser by serving a page with xml content.
Maybe I’m making this too complicated, does the remote client server request a page just like a browser would?
Thanks,
I am making this too complicated. I re-read the documentation, the remote client is just establishing a connection with a standard HTML POST header, so I guess I can just handle it the same as a browser submitting a form via POST.
To continue the train of thought;
The XML data transferred from the client is going to need to be parsed and placed into a table, should I receive the file into a variable and then parse it into the table in one shot, or would it be better practice to receive the data–>write out to temporary file on disk–>read and parse temporary file into database –> delete temporary file; basically separating the receiving and database write into separate operations?
Mark,
There is a benefit of caching the xml permanently as opposed to temporarily because if their feed goes down or for some reason or you can’t access it, the last loaded xml will still display.
E