<?php
//
// A very simple PHP example that sends a url to get short one
//
$s=microtime(true);
$myUrl='http://chart.apis.google.com/chart?chs=500x500&chma=0,0,100,100&cht=p&chco=FF0000%2CFFFF00%7CFF8000%2C00FF00%7C00FF00%2C0000FF&chd=t%3A122%2C42%2C17%2C10%2C8%2C7%2C7%2C7%2C7%2C6%2C6%2C6%2C6%2C5%2C5&chl=122%7C42%7C17%7C10%7C8%7C7%7C7%7C7%7C7%7C6%7C6%7C6%7C6%7C5%7C5&chdl=android%7Cjava%7Cstack-trace%7Cbroadcastreceiver%7Candroid-ndk%7Cuser-agent%7Candroid-webview%7Cwebview%7Cbackground%7Cmultithreading%7Candroid-source%7Csms%7Cadb%7Csollections%7Cactivity|Chart';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://lru.sh/");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('url' => $myUrl)));
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500); //The number of seconds to wait while trying to connect.
curl_setopt($ch, CURLOPT_TIMEOUT, 500); //The maximum number of seconds to allow cURL functions to execute.
// Receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close($ch);
$server_output_decoded = json_decode($server_output);
// Further processing ...
if (json_last_error() === JSON_ERROR_NONE) { //OK
// get short url
print $server_output_decoded->shorturl.' Done in '.round((microtime(true)-$s)*1000) .'ms';
} else { //KO
die('KO');
}
?>