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 ); ?>
Output for 7.4.0 - 7.4.1
Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 6 Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 58 Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 59 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(): open_basedir restriction in effect. File(https://144926223166432:x73txJkfqIlpoxB6IEeJyLLYIz8@api.cloudinary.com/v1_1/answ-cld/usage) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: Operation not permitted in /in/AGXA0 on line 42 Notice: Trying to access array offset on value of type null in /in/AGXA0 on line 45 Notice: Trying to access array offset on value of type null in /in/AGXA0 on line 45 Notice: Trying to access array offset on value of type null in /in/AGXA0 on line 46 Notice: Trying to access array offset on value of type null in /in/AGXA0 on line 46 Warning: file_put_contents(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 72 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Operation not permitted in /in/AGXA0 on line 72
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13
Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 6 Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 58 Warning: file_exists(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 59 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(): open_basedir restriction in effect. File(https://144926223166432:x73txJkfqIlpoxB6IEeJyLLYIz8@api.cloudinary.com/v1_1/answ-cld/usage) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 42 Warning: file_get_contents(https://...@api.cloudinary.com/v1_1/answ-cld/usage): failed to open stream: Operation not permitted in /in/AGXA0 on line 42 Warning: file_put_contents(): open_basedir restriction in effect. File(cloudinary_usage.json) is not within the allowed path(s): (/tmp:/in:/etc) in /in/AGXA0 on line 72 Warning: file_put_contents(cloudinary_usage.json): failed to open stream: Operation not permitted in /in/AGXA0 on line 72
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45
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.0.5, 5.1.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.3.11, 4.4.0 - 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

preferences:
214.56 ms | 402 KiB | 325 Q