robrichards / xmlseclibs

A PHP library for XML Security
BSD 3-Clause "New" or "Revised" License
387 stars 181 forks source link

Clear AMP cache using PHP #169

Closed ss84bhaskar closed 6 years ago

ss84bhaskar commented 6 years ago

Any help me to guide how i can purge AMP Cache for AMP URL?

Following is the code:

error_reporting(E_ALL); ini_set("display_errors", 1);

function urlsafe_b64encode($string) { return strreplace(array('+','/','='),array('-','',''), base64_encode($string)); }

$ampBaseUrl = "https://m-bhaskar-com.cdn.ampproject.org";

$signatureUrl = '/update-cache/c/s/m.bhaskar.com/amp/jharkhand/ranchi/news/JHA-RAN-HMU-LCL-infog-fodder-scam-lalu-prasad-yadav-including-19-convicts-will-announce-punishment-5836446-PHO.html?amp_action=flush&amp_ts='.time();

// opening the private key $pkeyid = openssl_pkey_get_private("file:///disk2/v/apache/htdocs/VIRTUAL/domains/www.bhaskar.com/public_html/.well-known/amphtml/apikey.pem");

// generating the signature openssl_sign($signatureUrl, $signature, $pkeyid);

// urlsafe base64 encoding $signature = urlsafe_b64encode($signature);

// final url for updating echo $ampUrl = $ampBaseUrl.$signatureUrl."&amp_url_signature=".$signature;

After Executing it gives Warning: openssl_sign(): supplied key param cannot be coerced into a private key

robrichards commented 6 years ago

Unsure how this is related to xmlseclibs.