Make Socket-based HTTP Calls Example

While the API does not include built-in calls for socket-based HTTP call, you can implement monitoring of socket-based HTTP exit calls yourself as shown in the following example:

<?php
function doSocketHTTPCall($url, $corrHeader = null)
{
$parts = parse_url($url);
$fs = @fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $error);
if (!$fs)
return null;
$send = "GET {$parts['path']} HTTP/1.1\r\n" .
"Host: {$parts['host']}\r\n" .
"Connection: Close\r\n";
if ($corrHeader)
$send .= "singularityheader: $corrHeader\r\n";
$send .= "\r\n";
fwrite($fs, $send);
$data = stream_get_contents($fs);
fclose($fs);
return $data;
}
$url = 'http://httpstat.us/200';
$parts = parse_url($url);
$exitCall = appdynamics_begin_exit_call(
AD_EXIT_HTTP,
'HTTP Status Service',
array('HOST' => $parts['host'],
'PORT' => (string)$parts['port'])
);
doSocketHTTPCall($url);
appdynamics_end_exit_call($exitCall);
?>