views:

236

answers:

1

Hi,

Want to be alerted when a secure remote proxy server stop working; for instance if Apache hangs for some reason.

As the remote machine will still be up, will still be able to ping, though this would prove very little.

Need to be able to script something that requests a path through the proxy and then returns the result.

Investigated PHP/PEAR Net library, thinking something like Net_traceroute() could be a starting point, but can't figure out how to force the route through the server.

Any ideas? Should I even be using PHP or would another language make this easier?

Cheers,

AJ

+1  A: 

If you want to make an HTTP request through the proxy, which I guess is the case because you mention Apache as the proxy?, then you could use cURL. Probably something like this:

<?php
$curl = curl_init('http://www.example.com');

//don't fetch the actual page, you only want to check the connection is ok
curl_setopt($curl, CURLOPT_NOBODY, true);

//stop it from outputting stuff to stdout
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

//proxy settings
curl_setopt($curl, CURLOPT_PROXYPORT, 8080);
curl_setopt($curl, CURLOPT_PROXY, 'proxyhost');
curl_setopt($curl, CURLOPT_PROXYUSERPWD, 'user:password');

$result = curl_exec($curl);

if ($result === false) {
    die (curl_error($curl)); 
}

There are more options for cURL documented here.

Tom Haigh