3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cloud_usage_file = "cloudinary_usage.json"; function primary($cloud_usage_file) { if ( !file_exists($cloud_usage_file) ) { write_to_file($cloud_usage_file); } else { clean_array($cloud_usage_file); write_to_file($cloud_usage_file); } } function clean_array($cloud_usage_file) { $json_obj = json_decode(file_get_contents($cloud_usage_file), TRUE); // delete repeat / indentical entries ... // $json_obj = array_unique($json_obj); foreach ($json_obj as $key => $value) { if (is_array($value)) { if ( strtotime($value[0]) < ( time() - 43200 ) ) { unset($json_obj[$key]); } } } $clean_json = json_encode($json_obj); file_put_contents($cloud_usage_file, $clean_json); } function entry_from_curl() { $curl_url = 'https://144926223166432:x73txJkfqIlpoxB6IEeJyLLYIz8@api.cloudinary.com/v1_1/answ-cld/usage'; $json_result = file_get_contents($curl_url); $usage_array = json_decode($json_result, true); $bandwidth_limit = $usage_array['bandwidth']['limit']; $bandwidth_use = $usage_array['bandwidth']['usage']; date_default_timezone_set("America/Los_Angeles"); // PST $friendly_date = date('Y-M-d H:m:s'); $temp_array = array( $friendly_date, $bandwidth_limit, $bandwidth_use); return $temp_array; } function write_to_file($cloud_usage_file) { $file_contents = file_exists($cloud_usage_file) ? file_get_contents($cloud_usage_file) : array(); $cloud_usage_array = file_exists($cloud_usage_file) ? json_decode($file_contents, TRUE) : array(); $entry_array = entry_from_curl(); if ( !is_null($cloud_usage_array) ) { array_push($cloud_usage_array, $entry_array); } else { $cloud_usage_array = $entry_array; } $json_mega_array = json_encode($cloud_usage_array); file_put_contents( $cloud_usage_file, $json_mega_array); } primary( $cloud_usage_file ); ?>

preferences:
32.51 ms | 402 KiB | 5 Q