WordPress Varnish plugin error

Was looking for a way to purge Varnish cache when pages are updated or added. WordPress Varnish plugin looks exactly like what I'm after, except it threw up some errors out of the box.

Errors:

Warning: fsockopen() expects parameter 2 to be long, string given in /path/to/wordpress-varnish/wp-varnish.php on line 138
()

and

Warning: fsockopen() expects parameter 2 to be long, string given in /path/to/wordpress-varnish/wp-varnish.php on line 115
()

My hack to fix the errors and also to add MU blogs to list of common URLs to purge on changes:

diff -up wp-varnish.php.default wp-varnish.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
--- wp-varnish.php.default	2010-05-10 17:20:25.000000000 -0700
+++ wp-varnish.php	2010-05-10 21:10:05.000000000 -0700
@@ -54,6 +54,13 @@ class WPVarnish {
     $this->WPVarnishPurgeObject("/");
     $this->WPVarnishPurgeObject("/feed/");
     $this->WPVarnishPurgeObject("/feed/atom/");
+    $this->WPVarnishPurgeObject("/alain/");
+    $this->WPVarnishPurgeObject("/alain/feed/");
+    $this->WPVarnishPurgeObject("/alain/feed/atom/");
+    $this->WPVarnishPurgeObject("/jason/");
+    $this->WPVarnishPurgeObject("/jason/feed/");
+    $this->WPVarnishPurgeObject("/jason/feed/atom/");
+
   }
 
   function WPVarnishAdminMenu() {
@@ -112,7 +119,7 @@ class WPVarnish {
     $wpv_host = preg_replace($wpv_replace_wpurl, "", $wpv_wpurl);
 
     for ($i = 0; $i < count ($wpv_purgeaddr); $i++) {
-      $varnish_sock = fsockopen($wpv_purgeaddr[$i], $wpv_purgeport[$i], $errno, $errstr, 30);
+      $varnish_sock = fsockopen("127.0.0.1", "80", $errno, $errstr, 30);
       if (!$varnish_sock) {
         echo "$errstr ($errno)<br />\n";
       } else {
@@ -135,7 +142,7 @@ class WPVarnish {
     $wpv_host = preg_replace($wpv_replace_wpurl, "", $wpv_wpurl);
 
     for ($i = 0; $i < count ($wpv_purgeaddr); $i++) {
-      $varnish_sock = fsockopen($wpv_purgeaddr[$i], $wpv_purgeport[$i], $errno, $errstr, 30);
+      $varnish_sock = fsockopen("127.0.0.1", "80", $errno, $errstr, 30);
       if (!$varnish_sock) {
         echo "$errstr ($errno)<br />\n";
       } else {

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).