varnish – Hitch installation completed with insserv errors. Unable to start hitch

I am trying to install hitch to terminate the certificates for the Varnish reverse proxy on my Ubuntu 16.04 VPS. The installation completes with the following messages and Hitch service doesnt startup.

sridhar@SastraTechnologies:~$ sudo apt install hitch
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libuv1
Use 'sudo apt autoremove' to remove it.
The following NEW packages will be installed:
  hitch
0 upgraded, 1 newly installed, 0 to remove and 100 not upgraded.
Need to get 0 B/51.1 kB of archives.
After this operation, 163 kB of additional disk space will be used.
Selecting previously unselected package hitch.
(Reading database ... 249839 files and directories currently installed.)
Preparing to unpack .../hitch_1.1.1-1_amd64.deb ...
Unpacking hitch (1.1.1-1) ...
Processing triggers for systemd (229-4ubuntu21.27) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up hitch (1.1.1-1) ...
insserv: Script nagios is broken: incomplete LSB comment.
insserv: missing `Default-Start:'  entry: please add even if empty.
insserv: missing `Default-Stop:'   entry: please add even if empty.
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `nagios'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `nagios'

Tried removing the packahe updating the repository and installing it again but the results are the same. Is there anything that I can do to resolve the insserv messages?

caching – Getting Miss always in varnish cache for the page using REST API

While hitting URL using REST API, it is always giving Miss for varnish cache for specific path and giving response from Memcahce. In header if we can check for cache-control we are getting “must-revalidate, no-cache, private”. Can someone guide us what exactly the issue or help us with the solution.

magento2.4 – Magento 2.4 Varnish error STACK OVERFLOW

I have a dockerised M2.4 installation. All worked fine with my theme and the installed extensions while working with Magento demo data. As soon as update the database with the live data I cannot get Varnish to work correctly. Contact page loads and non cached pages, but only the header will load for all other pages. Having checked the varnish container logs I see the following error below. It appears to be asking for more resources so I have updated /etc/default/varnish as follows:

DAEMON_OPTS=”-a :6081
-T localhost:6082
-f /etc/varnish/default.vcl
-S /etc/varnish/secret
-p thread_pool_stack=4096k
-p http_resp_hdr_len=65536
-p http_resp_size=98304
-p thread_pool_min=50
-p thread_pool_max=1000
-s malloc,256m”

Doesn’t seem to matter how high I set thread_pool_stack it still makes no difference. Any pointers or ideas much appreciated.

Debug: Child (8159) Started
Info: Child (8159) said Child starts
Error: Child (8159) died signal=6 (core dumped)
Error: Child (8159) Panic at: Thu, 22 Oct 2020 15:51:27 GMT
Wrong turn at cache/cache_main.c:284:
Signal 11 (Segmentation fault) received at 0x7f5bc4c56ff8 si_code 2
THIS PROBABLY IS A STACK OVERFLOW – check thread_pool_stack parameter
version = varnish-6.1.1 revision efc2f6c1536cf2272e471f5cff5f145239b19460, vrt api = 8.0
ident = Linux,5.4.0-26-generic,x86_64,-junix,-smalloc,-sdefault,-hcritbit,epoll
now = 691226.238573 (mono), 1603381887.549008 (real)
Backtrace:
0x55809884dd2a: varnishd(+0x4cd2a) (0x55809884dd2a)
0x5580988b5cc3: varnishd(VAS_Fail+0x13) (0x5580988b5cc3)
0x558098849736: varnishd(+0x48736) (0x558098849736)
0x7f5bd1505730: /lib/x86_64-linux-gnu/libpthread.so.0(+0x12730) (0x7f5bd1505730)
0x7f5bd16ea6d0: /lib/x86_64-linux-gnu/libpcre.so.3(+0x296d0) (0x7f5bd16ea6d0)
0x7f5bd17117d8: /lib/x86_64-linux-gnu/libpcre.so.3(+0x507d8) (0x7f5bd17117d8)
0x7f5bd16e84da: /lib/x86_64-linux-gnu/libpcre.so.3(pcre_exec+0x41a) (0x7f5bd16e84da)
0x5580988bceb0: varnishd(VRE_exec+0x80) (0x5580988bceb0)
0x558098866ac0: varnishd(VRT_regsub+0xd0) (0x558098866ac0)
0x7f5bc4d1cd91: vcl_boot.1603381053.170923471/vgc.so(VGC_function_vcl_recv+0x221) (0x7f5bc4d1cd91)
thread = (cache-worker)
thr.req = 0x7f5bc00aac20 {
vxid = 32772, transport = ESI_INCLUDE
step = R_STP_RECV,
req_body = R_BODY_NONE,
restarts = 0, esi_level = 1,
sp = 0x7f5bbfc01220 {
fd = 22, vxid = 32769,
t_open = 1603381885.250061,
t_idle = 1603381885.250061,
ws = 0x7f5bbfc01260 {
id = “ses”,
{s, f, r, e} = {0x7f5bbfc01298, +96, (nil), +352},
},
transport = HTTP/1 {
state = HTTP1::Proc
}
client = 172.27.0.9 55530 :80,
},
worker = 0x7f5bc4c605c0 {
ws = 0x7f5bc4c60668 {
id = “wrk”,
{s, f, r, e} = {0x7f5bc4c5f950, +264, (nil), +2040},
},
VCL::method = inside RECV,
VCL::return = 0x0,
VCL::methods = {RECV, HASH, MISS, DELIVER},
},
ws = 0x7f5bc00aad70 {
id = “req”,
{s, f, r, e} = {0x7f5bc00acca8, +80, (nil), +57168},
},
http_conn = 0x7f5bc00acc48 {
doclose = NULL,
ws = (nil) {
},
{rxbuf_b, rxbuf_e} = {(nil), (nil)},
{pipeline_b, pipeline_e} = {(nil), (nil)},
content_length = 0,
body_status = none,
first_byte_timeout = 0.000000,
between_bytes_timeout = 0.000000,
},
http(req) = 0x7f5bc00aae10 {
ws = 0x7f5bc00aad70 {
(Already dumped, see above)
},
hdrs {
“GET”,
“/page_cache/block/esi/blocks/%5B%22navpro.topnav%22%5D/handles/WyJkZWZhdWx0IiwiY21zX3BhZ2VfdmlldyJd/”,
“HTTP/1.1”,
“X-Real-IP: 172.27.0.1”,
“X-Forwarded-Proto: https”,
“X-Forwarded-Port: 443”,
“Ssl-Offloaded: 1”,
“DBG-SSL: 1”,
“Connection: close”,
“user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.80 Safari/537.36”,
“accept: /“,
“cookie: __tawkuuid=e%3A%3Aukled.co.uk%3A%3AVsBD2bF%2BVnVdKnq%2Fkt5XC9Nf3eQVlGCHWWPn5xBRC3JdwddvER%2ByIcjbl9XKGQwz%3A%3A2;AMCVS_8F99160E571FC0427F000101@AdobeOrg=1;cookies-policy=1;__stripe_mid=9dbda864-ad86-4bd8-8913-4be3ea9f43b31ecab6;s_cc=true;s_sq=%5B%5BB%5D%5D;persistent_shopping_cart=gJG70kPdvatyWYhmkNXxQ50fy7qFSCN3W6SX8ZYkICUrqzfvLN;private_content_version=c815c46799d2bce89504143f7b959a06;STVID=023172da-283c-3872-1fb7-1d8d94cee485;mage-cache-storage=%7B%7D;mage-cache-storage-section-invalidation=%7B%7D;mage-messages=;recently_viewed_product=%7B%7D;recently_viewed_product_previous=%7B%7D;recently_compared_product=%7B%7D;recently_compared_product_previous=%7B%7D;product_data_storage=%7B%7D;easybanner=%7B%22banner-argento-stripes-newsletter%22%3A%7B%22display_count_per_day%22%3A1%2C%22display_count%22%3A1%2C%22display_count_per_day_time%22%3A1603274902742%2C%22display_count_per_week_time%22%3A1603274902742%2C%22display_count_per_week%22%3A1%2C%22display_count_per_month_time%22%3A1603274902743%2C%22display_count_per_month%22%3A1%7D%7D;AMCV_8F99160E571FC0427F000101@AdobeOrg=1585540135%7CMCIDTS%7C18557%7CMCMID%7C08450058324156366094370300402754205863%7CMCAAMLH-1603959063%7C6%7CMCAAMB-1603959063%7CRKhpRz8krg2tLO6pguXWp5olkAcUniQYPHaMWWgdJ3xzPWQmdj0y%7CMCOPTOUT-1603361463s%7CNONE%7CvVersion%7C4.4.0;form_key=QWw4EVvfHIs60b7X;mage-cache-sessid=true;__extfc=1;X-Magento-Vary=2b7eda7bf5649669a3b54e524557cfe015428b43;_gat=1;TawkConnectionTime=0;CacheWarmer=CacheWarmer5f6b1fdb02569:eyJQRVJTSVNURU5UIjoxLCJjdXN0b21lcl9ncm91cCI6IjEifQ==prod_id_begin_0_prod_id_endcat_id_begin_0_cat_id_end;mst-cache-warmer-track=1”,
“Host: dev.ukled.co.uk”,
“Accept-Encoding: gzip”,
“X-Forwarded-For: 172.27.0.1, 172.27.0.9”,
“grace: none”,
},
},
vcl = {
name = “boot”,
busy = 3,
discard = 0,
state = auto,
temp = warm,
conf = {
srcname = {
“/etc/varnish/default.vcl”,
“Builtin”,
},
},
},
vmods = {
std = {Varnish 6.1.1 efc2f6c1536cf2272e471f5cff5f145239b19460, 0.0},
},
flags = {
},
privs = 0x7f5bc00aadf8 {
},
},
thr.busyobj = (nil) {
},

Debug: Child cleanup complete

magento2 – Magento 2.4 Varnish error 503

I got a copy of my Magento in another server, all checked permissions, vanilla installation, domain, but I don’t find the issue, I keep seeing this error message below.

Error 503 Backend fetch failed
Backend fetch failed

I found this reference from Magento but didn’t work.

https://support.magento.com/hc/en-us/articles/360034631211-Troubleshooting-503-errors

How could I fix it?

php – Storing session variable without interfering with Varnish

I have a form (www.example.com/form) that submits to a 3rd party app to add users to a contact list. The vendor does not provide any means of using AJAX, rather they allow you to specify a URL to redirect to after the form has processed. In an effort to have the UX of using this archaic form come as possible to functioning like an AJAX-enabled form, I am specifying the same page the form is on as the redirect page. I need to make it such that if the user filled out the form, a confirmation page will be displayed and if not, the form itself is displayed.

I am currently adding a query string parameter to the redirect URL (through the 3rd party app), so it looks something like www.exampe.com/form/?form_success=1. This way is easy enough to show the appropriate content (form or confirmation), but i don’t like the fact that someone could go to www.exampe.com/form/?form_success=1 without filling out the form.

I had the idea of making an AJAX call onSubmit that would do something to the effect of:

// JavaScript

$('form').submit(function() {     
   $.ajax({
      url:  admin-ajax.php
      method: 'post',
      action: 'handle_ajax_submit'
    },
    success: function() {
      return true;
    });
    return false;
});



// PHP

function handle_ajax_submit() {
  if (!session_id()) {
    session_start();
  }
  $_SESSION('form_submitted') = true;
}

I’d then use that value to determine which piece of content is displayed, form or confirmation. The problem with this is that my understanding is that the use of _SESSION prevents Varnish from caching the page, which i’d obviously like to avoid if possible.

Is there another”standard” way to handle this kind of situation in WordPress specifically? If not, would a standard cookie be the way to go here… or prhaps local storage? Both would require that AJAX call onSubmit, correct?

magento2 – Varnish cache always MISS on dynamic pages

Varnish doesn’t seem to be working properly for dynamic pages, it always returns a MISS in the response headers whether the request is coming from the browser or the CLI (curl/wget).

curl -IL -X GET ‘http://website.com/’

HTTP/1.1 200 OK
Date: Sun, 04 Oct 2020 10:45:45 GMT
Content-Type: text/html; charset=UTF-8
Vary: Accept-Encoding
Set-Cookie: PHPSESSID=aqhdrf2kemsc2n6uvv0a4m1j51; expires=Sun, 04-Oct-2020 11:45:45 GMT; Max-Age=3600; path=/; domain=website.com; HttpOnly
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
X-Cache: MISS
Pragma: no-cache
Expires: -1
Cache-Control: no-store, no-cache, must-revalidate, max-age=0
Accept-Ranges: bytes
Content-Length: 23297
Connection: keep-alive

However requests on static assets do hit varnish as expected:

curl -IL -X GET ‘http://website.com/static/frontend/Magento/blank/en_US/images/logo.svg’

HTTP/1.1 200 OK
Date: Sun, 04 Oct 2020 10:36:06 GMT
Content-Type: image/svg+xml
Last-Modified: Sat, 03 Oct 2020 20:48:21 GMT
Vary: Accept-Encoding
ETag: W/"5f78e395-f43"
Expires: Mon, 04 Oct 2021 10:36:06 GMT
Cache-Control: max-age=31536000, public
X-Frame-Options: SAMEORIGIN
X-Cache: HIT
X-Cache-Hits: 14
Accept-Ranges: bytes
Content-Length: 3907
Connection: keep-alive

I added the X-Cache and X-Cache-Hits headers to debug in production mode. This is a pretty stock version of Magento with no custom modules and using the blank theme. My default.vcl file is pretty much stock “Varnish 6” settings exported from the backend except for enabling caching static files and the debug response headers I included.

/etc/varnish/default.vcl

# VCL version 5.0 is not supported so it should be 4.0 even though actually used Varnish version is 6
vcl 4.0;

import std;
# The minimal Varnish version is 6.0
# For SSL offloading, pass the following header in your proxy server or load balancer: 'X-Forwarded-Proto: https'

backend default {
    .host = "localhost";
    .port = "8080";
    .first_byte_timeout = 600s;
    .probe = {
        .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

acl purge {
    "localhost";
}

sub vcl_recv {
    if (req.method == "PURGE") {
        if (client.ip !~ purge) {
            return (synth(405, "Method not allowed"));
        }
        # To use the X-Pool header for purging varnish during automated deployments, make sure the X-Pool header
        # has been added to the response in your backend server config. This is used, for example, by the
        # capistrano-magento2 gem for purging old content from varnish during it's deploy routine.
        if (!req.http.X-Magento-Tags-Pattern && !req.http.X-Pool) {
            return (synth(400, "X-Magento-Tags-Pattern or X-Pool header required"));
        }
        if (req.http.X-Magento-Tags-Pattern) {
          ban("obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);
        }
        if (req.http.X-Pool) {
          ban("obj.http.X-Pool ~ " + req.http.X-Pool);
        }
        return (synth(200, "Purged"));
    }

    if (req.method != "GET" &&
        req.method != "HEAD" &&
        req.method != "PUT" &&
        req.method != "POST" &&
        req.method != "TRACE" &&
        req.method != "OPTIONS" &&
        req.method != "DELETE") {
          /* Non-RFC2616 or CONNECT which is weird. */
          return (pipe);
    }

    # We only deal with GET and HEAD by default
    if (req.method != "GET" && req.method != "HEAD") {
        return (pass);
    }

    # Bypass shopping cart, checkout and search requests
    if (req.url ~ "/checkout" || req.url ~ "/catalogsearch") {
        return (pass);
    }

    # Bypass health check requests
    if (req.url ~ "/pub/health_check.php") {
        return (pass);
    }

    # Set initial grace period usage status
    set req.http.grace = "none";

    # normalize url in case of leading HTTP scheme and domain
    set req.url = regsub(req.url, "^http(s)?://", "");

    # collect all cookies
    std.collect(req.http.Cookie);

    # Compression filter. See https://www.varnish-cache.org/trac/wiki/FAQ/Compression
    if (req.http.Accept-Encoding) {
        if (req.url ~ ".(jpg|jpeg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|swf|flv)$") {
            # No point in compressing these
            unset req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate" && req.http.user-agent !~ "MSIE") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unknown algorithm
            unset req.http.Accept-Encoding;
        }
    }

    # Remove all marketing get parameters to minimize the cache objects
    if (req.url ~ "(?|&)(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_(a-z)+|utm_(a-z)+|_bta_(a-z)+)=") {
        set req.url = regsuball(req.url, "(gclid|cx|ie|cof|siteurl|zanpid|origin|fbclid|mc_(a-z)+|utm_(a-z)+|_bta_(a-z)+)=(-_A-z0-9+()%.)+&?", "");
        set req.url = regsub(req.url, "(?|&)+$", "");
    }

    # Static files caching
    if (req.url ~ "^/(pub/)?(media|static)/") {
        # Static files should not be cached by default
        #return (pass);

        # But if you use a few locales and don't use CDN you can enable caching static files by commenting previous line (#return (pass);) and uncommenting next 3 lines
        unset req.http.Https;
        unset req.http.X-Forwarded-Proto;
        unset req.http.Cookie;
    }

    return (hash);
}

sub vcl_hash {
    if (req.http.cookie ~ "X-Magento-Vary=") {
        hash_data(regsub(req.http.cookie, "^.*?X-Magento-Vary=((^;)+);*.*$", "1"));
    }

    # For multi site configurations to not cache each other's content
    if (req.http.host) {
        hash_data(req.http.host);
    } else {
        hash_data(server.ip);
    }

    # To make sure http users don't see ssl warning
    if (req.http.X-Forwarded-Proto) {
        hash_data(req.http.X-Forwarded-Proto);
    }


    if (req.url ~ "/graphql") {
        call process_graphql_headers;
    }
}

sub process_graphql_headers {
    if (req.http.Store) {
        hash_data(req.http.Store);
    }
    if (req.http.Content-Currency) {
        hash_data(req.http.Content-Currency);
    }
}

sub vcl_backend_response {

    set beresp.grace = 3d;

    if (beresp.http.content-type ~ "text") {
        set beresp.do_esi = true;
    }

    if (bereq.url ~ ".js$" || beresp.http.content-type ~ "text") {
        set beresp.do_gzip = true;
    }

    if (beresp.http.X-Magento-Debug) {
        set beresp.http.X-Magento-Cache-Control = beresp.http.Cache-Control;
    }

    # cache only successfully responses and 404s
    if (beresp.status != 200 && beresp.status != 404) {
        set beresp.ttl = 0s;
        set beresp.uncacheable = true;
        return (deliver);
    } elsif (beresp.http.Cache-Control ~ "private") {
        set beresp.uncacheable = true;
        set beresp.ttl = 86400s;
        return (deliver);
    }

    # validate if we need to cache it and prevent from setting cookie
    if (beresp.ttl > 0s && (bereq.method == "GET" || bereq.method == "HEAD")) {
        unset beresp.http.set-cookie;
    }

   # If page is not cacheable then bypass varnish for 2 minutes as Hit-For-Pass
   if (beresp.ttl <= 0s ||
       beresp.http.Surrogate-control ~ "no-store" ||
       (!beresp.http.Surrogate-Control &&
       beresp.http.Cache-Control ~ "no-cache|no-store") ||
       beresp.http.Vary == "*") {
        # Mark as Hit-For-Pass for the next 2 minutes
        set beresp.ttl = 120s;
        set beresp.uncacheable = true;
    }

    return (deliver);
}

sub vcl_deliver {
    if (resp.http.X-Magento-Debug) {
        if (resp.http.x-varnish ~ " ") {
            set resp.http.X-Magento-Cache-Debug = "HIT";
            set resp.http.Grace = req.http.grace;
        } else {
            set resp.http.X-Magento-Cache-Debug = "MISS";
        }
    } else {
        unset resp.http.Age;
    }

    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
        set resp.http.X-Cache-Hits = obj.hits;
    }
    else {
        set resp.http.X-Cache = "MISS";
    }

    # Not letting browser to cache non-static files.
    if (resp.http.Cache-Control !~ "private" && req.url !~ "^/(pub/)?(media|static)/") {
        set resp.http.Pragma = "no-cache";
        set resp.http.Expires = "-1";
        set resp.http.Cache-Control = "no-store, no-cache, must-revalidate, max-age=0";
    }

    unset resp.http.X-Magento-Debug;
    unset resp.http.X-Magento-Tags;
    unset resp.http.X-Powered-By;
    unset resp.http.Server;
    unset resp.http.X-Varnish;
    unset resp.http.Via;
    unset resp.http.Link;
}

sub vcl_hit {
    if (obj.ttl >= 0s) {
        # Hit within TTL period
        return (deliver);
    }
    if (std.healthy(req.backend_hint)) {
        if (obj.ttl + 300s > 0s) {
            # Hit after TTL expiration, but within grace period
            set req.http.grace = "normal (healthy server)";
            return (deliver);
        } else {
            # Hit after TTL and grace expiration
            return (restart);
        }
    } else {
        # server is not healthy, retrieve from cache
        set req.http.grace = "unlimited (unhealthy server)";
        return (deliver);
    }
}

Also my config settings in the backend:

Full Page Cache

Caching Application: Varnish Cache (Recommended)
TTL for public content: 86400
Access list: localhost
Backend host: localhost
Backend port: 8080
Grace period: 300

I checked the whole response XML and there’s no cacheable="false" being set, I found odd that the Cache-Control header is set to no-cache but that seems to be the behaviour the VCL file sets for non-static files by default.

Any advice on what to do?

magento2 – Setting varnish full page cache settings via environment variables

I’m trying to set the varnish settings through environmental variables. I have the following ones set:

CONFIG__DEFAULT__SYSTEM__FULL_PAGE_CACHE__VARNISH__BACKEND_HOST: varnish-service
CONFIG__DEFAULT__SYSTEM__FULL_PAGE_CACHE__VARNISH__BACKEND_PORT: 8090

If I go to the settings for Full Page Cache I can verify that it’s set to the above mentioned values. See image below.

full page cache settings

My problem comes when I’m trying to run bin/magento cache:clean. In my system.log I get the following error: main.CRITICAL: Unable to connect to varnish:80 . Error #0: stream_socket_client(): unable to connect to varnish:80. As you can see these values are not respected when cleaning the cache.

To solve this for now I need to run bin/magento setup:config:set --http-cache-hosts=varnish-service:8090 which solves the issue but I would still like Magento2 to respect the values I set through the environment variables so I can control it without running commands on the containers.

Magento version is 2.3.1 and I’m running my containers in Kubernetes.

How to add Varnish VCL rule in Magento Cloud?

I need to add a new VCL rule in my Magento Cloud 2.4, I’m using Fastly to have Varnish.

How could I customize my Varnish configurations in Magento?

Magento bitnami linux Setup Varnish

I want to configure and use : https://devdocs.magento.com/guides/v2.3/config-guide/varnish/config-varnish.html
for Magento in bitnami Linux

caching – Convert Acquia Clear Varnish For One URL Curl Command to Drupal::httpClient()

I am trying to convert a command to php curl or Drupal::httpClient().

The original command

Curl -k -X PURGE -H "X-Acquia-Purge:(site-name)" --compressed -H "Host: example.com" https://bal-12345.prod.hosting.acquia.com/my-url

Here is the conversion I tried (but it is not working) This one returns 200 status code but it is not working.

$varnishUrl = "https://bal-12345.prod.hosting.acquia.com/my-url"
$headers = (
  'X-Acquia-Purge'  => "site-name",
  'Host'            => "example.com"
);
$options = ('headers' => $headers, 'body' => $varnishUrl);
try {
  $client = Drupal::httpClient();
  $response = $client->request('PURGE', $domainUrl, $options);
  $code = $response->getStatusCode();
  if ($code == 200) {
    return $code;
  }
}
catch (RequestException $e) {
  watchdog_exception('module_name', $e);
}

This is the second conversion to php and also not working.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $varnishUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PURGE');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers() = 'X-Acquia-Purge: site-name';
$headers() = 'Host: example.com';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_exec($ch);
curl_close($ch);

I would appreciate any input.