apache - Varnish POST cache not working though PHP CURL, however, it seems to be working with TERMINAL CURL
one text
Solution:
I notice a discrepancy between the POST data on the command line and the data in the PHP script.
The --data '{"maxresults":2000}'
in your cURL request will actually send a JSON object as payload.
When I look at your PHP script, $data['maxresults'] = 2000;
is just regular POST data, which is not the same.
Because you perform a bodyaccess.hash_req_body();
in vcl_hash
, the lookup hash will be different if the POST body is different. That's why you'll get a miss in your script.
JSON payload
If you want the same result, I'd advise you to set the POST fields as follows:
curl_setopt($s,CURLOPT_POSTFIELDS,json_encode($data));
Regular POST fields
If you want to use regular POST fields instead, you can perform the following cURL call on the command line:
curl --data 'maxresults=2000' http://localhost/varnishoutput/varnishtest.php
And this is the change you need to make in your PHP file if you want to use pure POST fields:
curl_setopt($s,CURLOPT_POSTFIELDS,http_build_query($data));
Source