Note (2025): This post was written in 2010. The sample uses ereg, which has been deprecated in PHP 5.3 and removed as of PHP 7. Use preg_match or other modern approaches for production code. The article remains here for archival and historical interest.

Sometimes you need to understand precisely how the HTTP request is submitted to the server. If you’re working with Salesforce.com, you probably don’t have easy or intuitive tools to understand how a message is serialized and sent by the runtime to the server.

I’ve put together this little script that allows you to log all HTTP requests to a file. It becomes much easier to verify the output sent to a web service.

<?php
    $myFile = "requestslog.txt";
    $fh = fopen($myFile, 'a') or die("can't open file");
    fwrite($fh, "\n\n--------------------------------------\n");
    foreach($_SERVER as $h => $v) {
        if (preg_match('/^HTTP_(.+)/', $h, $hp)) {
            fwrite($fh, "$h = $v\n");
        }
    }
    fwrite($fh, "\r\n");
    fwrite($fh, file_get_contents('php://input'));
    fclose($fh);
    echo "<html><head /><body><iframe src=\"$myFile\" style=\"height:100%; width:100%;\"></iframe></body></html>";
?>

This applies to all requests that travel with the HTTP protocol, even SOAP, for instance.