Tuesday, July 10, 2007

Sending XML files to a Webservice (Using cURL)

Calling Web Services. Great fun!! … when it works. One of the biggest challenges is to send the XML document and get the response back, an XML document in particular. I have come up with a PHP function that hides all the necessary logic from theuser and handles the posting of the XML document and returns whatever the server responds. It relies on PHP’s cURL library (so you need it properly configured on your server in order to work). All you need to do is create the XML document, choose the URL (and port) to which you want to post the XML document and the function takes care of the rest. Below is the function code. As you can see, the function can handle SSL-enabled servers, something that provides a great advantage, since many Web services run on HTTPS.

// open a http channel, transmit data and return received buffer
function xml_post($post_xml, $url, $port)
{
$user_agent = $_SERVER[’HTTP_USER_AGENT’];
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, $port); //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
if($port==443)
{
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
}
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

The example below shows how the function works, by posting a XML document of the form
<?xml version=”1.0″ encoding=”iso-8859-1″?>

<Document>

<Message>

Your Name

</Message>

</Document>
to a “listener” script, which takes the XML document and returns a reply (another XML document). In this case, the listener is very simple. All it does is replace the “Message” tag with “Reply” and print the resulting XML. Of course, the listener can do all sorts of things in response to the POST.

<?php

if ( !isset( $HTTP_RAW_POST_DATA ) )

{

$HTTP_RAW_POST_DATA = file_get_contents( ‘php://input’ );

}

$xml = str_replace(”Message”,”Reply” , $HTTP_RAW_POST_DATA);


print((trim($xml)));

?>



You can download the function code, as well as a working example here. Let me know what you think.

Thursday, July 5, 2007


The Granite™ USB 2.0 HIGH-SPEED Bridge Adapter allows any 2.5", 3.5" or 5.25" SATA or IDE Drive to quickly be attached to any computer. This is the perfect tool to duplicate, copy, backup, or transfer large amount of data from one drive to another.

Easy to take to any location and universal enough to work with any system.ultra fast USB 2.0 transfers data at up to 480Mbps and connects to any computer.The Standard Kit includes a Dual Output Drive Power Supply and USB to SATA / IDE adapter while the Deluxe Kit includes two Dual Output Drive Power Supplies, two USB to SATA / IDE adapters, padded carrying case, 4 Port USB Hub, and Auxiliary Power Cable making it easy to work with two drive mechanisms at once.



USB 2.0 Hi-Speed & USB 1.0

480 Mbit/s Data Transfer

Switched Dual Output Power

ATA 6 Large Drive Support

One Year Warranty

Microsoft Mouse

Do more and carry less with the first ever Notebook Mouse with integrated slide presenter, laser pointer, and media remote control. It's an all-in-one super tool for the office, road, and home—the only input device you need.
Presentation Controls more

Smoothly navigate through Microsoft Office PowerPoint® and other presentations from up to 30 feet away from your PC.


Media Remote more

Use for multimedia presentations and control digital entertainment from the comfort of your living room sofa.

Battery Life Indicator more

You won't get caught with a dead battery—the Battery Status LED Indicator glows red when the battery is running low.

2.4 GHz Bluetooth® with First Connect Technology more

Connect wirelessly right out of the box with 2.4 GHz Bluetooth®.

High Definition Laser Technology more

Microsoft® High Definition Laser Mouse products are more precise, more responsive, and deliver smoother tracking.

Laser Pointer more

Point out essential information during presentations with the laser pointer.

» See all features

Wednesday, July 4, 2007

What a Computer Does

The instructions in the program direct the computer to input, process and output as follows:

Input/Output

The computer can selectively retrieve data into its main memory (RAM) from any peripheral device (terminal, disk, tape, etc.) connected to it. After processing the data internally, the computer can send a copy of the results from its memory out to any peripheral device. The more memory it has, the more programs and data it can work with at the same time.

Storage

By outputting data onto a magnetic disk or tape, the computer is able to store data permanently and retrieve it when required. A system's size is based on how much disk storage it has. The more disk, the more data are immediately available.
Processing (The 3 C's)
The computer performs all processing by "calculating," "comparing" and "copying" the data stored in its memory (RAM).

Calculate

The computer can perform any mathematical operation on data by adding, subtracting, multiplying and dividing one set with another.

Compare

The computer can analyze and evaluate data by matching it with sets of known data that are included in the program or called in from storage.

Copy

The computer can move data around to create any kind of report or listing in any order.
Calculate, Compare and Copy
By calculating, comparing and copying, the computer accomplishes all forms of data processing. For example, records are sorted into a new order by comparing two records at a time and copying the record with the lower value in front of the one with the higher value.
The computer finds one customer out of thousands by comparing the requested account number to each record in the file. The query statement: SUM SALARY FOR TITLE = "NURSE" causes the computer to compare the title field in each record for NURSE and then add (calculate) the salary field for each match.
In word processing, inserting and deleting text is accomplished by copying characters from one place to another.

Computer

A device that receives, processes, and presents information. The two basic types of computers are analog and digital. Although generally not regarded as such, the most prevalent computer is the simple mechanical analog computer, in which gears, levers, ratchets, and pawls perform mathematical operations—for example, the speedometer and the watt-hour meter (used to measure accumulated electrical usage). The general public has become much more aware of the digital computer with the rapid proliferation of the hand-held calculator and a large variety of intelligent devices and especially with exposure to the Internet and the World Wide Web. See also Calculators; Internet; World Wide Web.
An analog computer uses inputs that are proportional to the instantaneous value of variable quantities, combines these inputs in a predetermined way, and produces outputs that are a continuously varying function of the inputs and the processing. These outputs are then displayed or connected to another device to cause action, as in the case of a speed governor or other control device. Small electronic analog computers are frequently used as components in control systems. If the analog computer is built solely for one purpose, it is termed a special-purpose electronic analog computer. In any analog computer the key concepts involve special versus general-purpose computer designs, and the technology utilized to construct the computer itself, mechanical or electronic. See also Analog computer.
In contrast, a digital computer uses symbolic representations of its variables. The arithmetic unit is constructed to follow the rules of one (or more) number systems. Further, the digital computer uses individual discrete states to represent the digits of the number system chosen. A digital computer can easily store and manipulate numbers, letters, images, sounds, or graphical information represented by a symbolic code. Through the use of the stored program, the digital computer achieves a degree of flexibility unequaled by any other computing or data-processing device.
The advent of the relatively inexpensive and readily available personal computer, and the combination of the computer and communications, such as by the use of networks, have dramatically expanded computer applications. The most common application now is probably text and word processing, followed by electronic mail. See also Electronic mail; Local-area networks; Microcomputer; Word processing.
Computers have begun to meet the barrier imposed by the speed of light in achieving higher speeds. This has led to research and development in the areas of parallel computers (in order to accomplish more in parallel rather than by serial computation) and distributed computers (taking advantage of network connections to spread the work around, thus achieving more parallelism). Continuing demand for more processing power has led to significant changes in computer hardware and software architectures, both to increase the speed of basic operations and to reduce the overall processing time. See also Computer systems architecture; Concurrent processing; Distributed systems (computers); Multiprocessing; Supercomputer.

Sunday, July 1, 2007

What is Computer Hardware?

Refers to objects that you can actually touch, like disks, disk drives, display screens, keyboards, printers, boards, and chips. In contrast, software is untouchable. Software exists as ideas, concepts, and symbols, but it has no substance.
Books provide a useful analogy. The pages and the ink are the hardware, while the words, sentences, paragraphs, and the overall meaning are the software. A computer without software is like a book full of blank pages -- you need software to make the computer useful just as you need words to make a book meaningful.