Now that you've understood the fundamentals, let's look at a simple application of WDDX. One of the most popular uses of this type of technology involves using it to get and display syndicated content from a content provider. Since WDDX is designed expressly for transferring data in a standard format, it excels at this type of task - in fact, the entire process can be accomplished via two very simple scripts, one running on the news server and the other running on the client. Let's look at the server component first. We'll begin with the assumption that the content to be distributed (news headlines, in this case) are stored in a single database table, which is updated on a regular basis from an external data source. Every headline has a timestamp, which helps to identify the most recent. Consequently, we can postulate a table which looks something like this: Now, we need to write a script which will reside on the server, connect to this table, retrieve the four most recent headlines, and encode them as a WDDX packet This is an extremely simple script - it performs a query to get the four most recent headlines, adds them to an array named $serverSlugArray, and then serializes and prints this array as a WDDX packet. The requesting client now needs only to send a HTTP request to this script, read and deserialize the generated WDDX packet, and use it in whatever manner it sees fit. For this example, I'm using the data to create a scrollable tickertape containing the news items. The first three lines are the most important - they take care of reading the URL into a single string (using standard file functions) and deserializing the WDDX packet into a native PHP array called $clientSlugArray. The remainder of the script simply iterates through this array and prints the elements (news headlines) within a <marquee> tag. As you can see, using WDDX as the transport mechanism between servers offers a number of advantages - it's simple, flexible and far more efficient than coding your own solution to the problem. In fact, for certain business applications - content syndication is a prime example - it can save you a great deal of development and testing time.
blog comments powered by Disqus |