curl - Using Google Url Shortener service from PHP: how to improve performance using gzip? -
i'm using google url shortener service in php code.
it's working i'd improve performances , i've seen documentation (rif. https://developers.google.com/url-shortener/v1/performance) suggests working partial resources , using gzip.
i've adopted partial resources approach , works fine i'd use gzip suggestion too.
by code is
function compacturl($longurl) { $apikey = api; $postdata = array('longurl' => $longurl); $jsondata = json_encode($postdata); $curlobj = curl_init(); curl_setopt($curlobj, curlopt_url, 'https://www.googleapis.com/urlshortener/v1/url?key='.$apikey'&fields=id); curl_setopt($curlobj, curlopt_returntransfer, 1); curl_setopt($curlobj, curlopt_ssl_verifypeer, 0); curl_setopt($curlobj, curlopt_header, 0); curl_setopt($curlobj, curlopt_httpheader, array('content-type:application/json')); curl_setopt($curlobj, curlopt_post, 1); curl_setopt($curlobj, curlopt_postfields, $jsondata); $response = curl_exec($curlobj); //print 'response = '.$response; // change response json string object $json = json_decode($response); curl_close($curlobj); $shortlink = get_object_vars($json); return $shortlink['id']; }
the google documentation says use
accept-encoding: gzip user-agent: program (gzip)
my problem don't know how convert in php code ......
any suggestions?
thank in advance!!!
cesare
Comments
Post a Comment