Using wordpress through a proxy server

Where the web server hosting the WordPress site is located behind a proxy server, the WordPress admin and user may experience technical problems. Symptoms include:

– very slow loading of the dashboard
– askimet not working

These can be resolved by first setting proxy credentials in wp-includes/class-snoopy.php and then editing the akismet_http_post function in wp-content/plugins/askimet/askimet.php along the lines suggested at:

http://comox.textdrive.com/pipermail/wp-trac/2006-August/003435.html

Where your proxy server requires authentication you will need to provide this in askimet.php using the line:

$http_request .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode _
('username:password')."rn";

remembering to substitute in your actual username and password.

The new akismet_http_post function should therefore be:

function akismet_http_post($request, $host, $path, $port = 80) { _
 global $wp_version;

// $http_request  = "POST $path HTTP/1.0rn";
// $http_request .= "Host: $hostrn";
 $http_request  = "POST http://$host$path HTTP/1.0rn";
 $http_request .= "Host: http://$hostrn";

$http_request .= "Content-Type: application/x-www-form-urlencoded; _
charset=" . get_option('blog_charset') . "rn";
 $http_request .= "Content-Length: " . strlen($request) . "rn";
$http_request .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode_
 'username:password')."rn";

 $http_request .= "User-Agent: WordPress/$wp_version | Akismet/2.0rn";
 $http_request .= "rn";
 $http_request .= $request;

 $response = '';
// if( false != ( $fs = @fsockopen($host, $port, $errno, $errstr, 10) ) ) {
 if( false !== ( $fs = @fsockopen('your_proxy_address', your_proxy_port, _
$errno, $errstr, 10) ) ) {

  fwrite($fs, $http_request);

  while ( !feof($fs) )
   $response .= fgets($fs, 1160); // One TCP-IP packet
  fclose($fs);
  $response = explode("rnrn", $response, 2);
 }
 return $response;
}

4 Replies

Reply to Imran Mehroz Cancel

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.