3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 ); ?>
based on m1XrE
Output for 5.4.15 - 5.6.28, 7.0.0 - 7.1.0
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /in/AGXA0 on line 42 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Permission denied in /in/AGXA0 on line 72
Output for hhvm-3.10.0 - 3.12.0
Warning: Failed to open https://144926223166432:x73txJkfqIlpoxB6IEeJyLLYIz8@api.cloudinary.com/v1_1/answ-cld/usage (Could not resolve host: api.cloudinary.com) in /in/AGXA0 on line 42 Warning: Permission denied in /in/AGXA0 on line 72
Output for 5.3.0 - 5.4.14
Warning: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Permission denied in /in/AGXA0 on line 72
Output for 5.2.3 - 5.2.17
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Permission denied in /in/AGXA0 on line 72
Output for 5.2.0 - 5.2.2
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Read-only file system in /in/AGXA0 on line 72
Output for 5.0.0 - 5.1.6
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Fatal error: Call to undefined function json_decode() in /in/AGXA0 on line 43
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Fatal error: Call to undefined function: json_decode() in /in/AGXA0 on line 43
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Notice: file_get_contents(): Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: No such file or directory in /in/AGXA0 on line 42 Fatal error: Call to undefined function: json_decode() in /in/AGXA0 on line 43
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: file_get_contents() [http://www.php.net/function.file-get-contents]: Unable to find the wrapper "https" - did you forget to enable it when you configured PHP? in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage) [http://www.php.net/function.file-get-contents]: failed to create stream: No such file or directory in /in/AGXA0 on line 42 Fatal error: Call to undefined function: json_decode() in /in/AGXA0 on line 43