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 ); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGXA0
function name:  (null)
number of ops:  5
compiled vars:  !0 = $cloud_usage_file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'cloudinary_usage.json'
   75     1        INIT_FCALL                                               'primary'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0          
   77     4      > RETURN                                                   1

Function primary:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 10
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 16
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGXA0
function name:  primary
number of ops:  17
compiled vars:  !0 = $cloud_usage_file
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
    6     1        INIT_FCALL                                               'file_exists'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        BOOL_NOT                                         ~2      $1
          5      > JMPZ                                                     ~2, ->10
    8     6    >   INIT_FCALL_BY_NAME                                       'write_to_file'
          7        SEND_VAR_EX                                              !0
          8        DO_FCALL                                      0          
          9      > JMP                                                      ->16
   12    10    >   INIT_FCALL_BY_NAME                                       'clean_array'
         11        SEND_VAR_EX                                              !0
         12        DO_FCALL                                      0          
   13    13        INIT_FCALL_BY_NAME                                       'write_to_file'
         14        SEND_VAR_EX                                              !0
         15        DO_FCALL                                      0          
   15    16    > > RETURN                                                   null

End of function primary

Function clean_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 25
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 24
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 24
Branch analysis from position: 23
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 24
Branch analysis from position: 24
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/AGXA0
function name:  clean_array
number of ops:  35
compiled vars:  !0 = $cloud_usage_file, !1 = $json_obj, !2 = $value, !3 = $key, !4 = $clean_json
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     1        INIT_FCALL                                               'json_decode'
          2        INIT_FCALL                                               'file_get_contents'
          3        SEND_VAR                                                 !0
          4        DO_ICALL                                         $5      
          5        SEND_VAR                                                 $5
          6        SEND_VAL                                                 <true>
          7        DO_ICALL                                         $6      
          8        ASSIGN                                                   !1, $6
   24     9      > FE_RESET_R                                       $8      !1, ->25
         10    > > FE_FETCH_R                                       ~9      $8, !2, ->25
         11    >   ASSIGN                                                   !3, ~9
   26    12        TYPE_CHECK                                  128          !2
         13      > JMPZ                                                     ~11, ->24
   28    14    >   INIT_FCALL                                               'strtotime'
         15        FETCH_DIM_R                                      ~12     !2, 0
         16        SEND_VAL                                                 ~12
         17        DO_ICALL                                         $13     
         18        INIT_FCALL                                               'time'
         19        DO_ICALL                                         $14     
         20        SUB                                              ~15     $14, 43200
         21        IS_SMALLER                                               $13, ~15
         22      > JMPZ                                                     ~16, ->24
   30    23    >   UNSET_DIM                                                !1, !3
   24    24    > > JMP                                                      ->10
         25    >   FE_FREE                                                  $8
   35    26        INIT_FCALL                                               'json_encode'
         27        SEND_VAR                                                 !1
         28        DO_ICALL                                         $17     
         29        ASSIGN                                                   !4, $17
   36    30        INIT_FCALL                                               'file_put_contents'
         31        SEND_VAR                                                 !0
         32        SEND_VAR                                                 !4
         33        DO_ICALL                                                 
   37    34      > RETURN                                                   null

End of function clean_array

Function entry_from_curl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AGXA0
function name:  entry_from_curl
number of ops:  29
compiled vars:  !0 = $curl_url, !1 = $json_result, !2 = $usage_array, !3 = $bandwidth_limit, !4 = $bandwidth_use, !5 = $friendly_date, !6 = $temp_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ASSIGN                                                   !0, 'https%3A%2F%2F144926223166432%3Ax73txJkfqIlpoxB6IEeJyLLYIz8%40api.cloudinary.com%2Fv1_1%2Fansw-cld%2Fusage'
   42     1        INIT_FCALL                                               'file_get_contents'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $8      
          4        ASSIGN                                                   !1, $8
   43     5        INIT_FCALL                                               'json_decode'
          6        SEND_VAR                                                 !1
          7        SEND_VAL                                                 <true>
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !2, $10
   45    10        FETCH_DIM_R                                      ~12     !2, 'bandwidth'
         11        FETCH_DIM_R                                      ~13     ~12, 'limit'
         12        ASSIGN                                                   !3, ~13
   46    13        FETCH_DIM_R                                      ~15     !2, 'bandwidth'
         14        FETCH_DIM_R                                      ~16     ~15, 'usage'
         15        ASSIGN                                                   !4, ~16
   48    16        INIT_FCALL                                               'date_default_timezone_set'
         17        SEND_VAL                                                 'America%2FLos_Angeles'
         18        DO_ICALL                                                 
   49    19        INIT_FCALL                                               'date'
         20        SEND_VAL                                                 'Y-M-d+H%3Am%3As'
         21        DO_ICALL                                         $19     
         22        ASSIGN                                                   !5, $19
   51    23        INIT_ARRAY                                       ~21     !5
         24        ADD_ARRAY_ELEMENT                                ~21     !3
         25        ADD_ARRAY_ELEMENT                                ~21     !4
         26        ASSIGN                                                   !6, ~21
   53    27      > RETURN                                                   !6
   54    28*     > RETURN                                                   null

End of function entry_from_curl

Function write_to_file:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 10
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 35
Branch analysis from position: 30
Branch analysis from position: 35
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 22
Branch analysis from position: 16
Branch analysis from position: 22
filename:       /in/AGXA0
function name:  write_to_file
number of ops:  45
compiled vars:  !0 = $cloud_usage_file, !1 = $file_contents, !2 = $cloud_usage_array, !3 = $entry_array, !4 = $json_mega_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
   58     1        INIT_FCALL                                               'file_exists'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $5      
          4      > JMPZ                                                     $5, ->10
          5    >   INIT_FCALL                                               'file_get_contents'
          6        SEND_VAR                                                 !0
          7        DO_ICALL                                         $6      
          8        QM_ASSIGN                                        ~7      $6
          9      > JMP                                                      ->11
         10    >   QM_ASSIGN                                        ~7      <array>
         11    >   ASSIGN                                                   !1, ~7
   59    12        INIT_FCALL                                               'file_exists'
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $9      
         15      > JMPZ                                                     $9, ->22
         16    >   INIT_FCALL                                               'json_decode'
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 <true>
         19        DO_ICALL                                         $10     
         20        QM_ASSIGN                                        ~11     $10
         21      > JMP                                                      ->23
         22    >   QM_ASSIGN                                        ~11     <array>
         23    >   ASSIGN                                                   !2, ~11
   60    24        INIT_FCALL                                               'entry_from_curl'
         25        DO_FCALL                                      0  $13     
         26        ASSIGN                                                   !3, $13
   62    27        TYPE_CHECK                                    2  ~15     !2
         28        BOOL_NOT                                         ~16     ~15
         29      > JMPZ                                                     ~16, ->35
   64    30    >   INIT_FCALL                                               'array_push'
         31        SEND_REF                                                 !2
         32        SEND_VAR                                                 !3
         33        DO_ICALL                                                 
         34      > JMP                                                      ->36
   68    35    >   ASSIGN                                                   !2, !3
   71    36    >   INIT_FCALL                                               'json_encode'
         37        SEND_VAR                                                 !2
         38        DO_ICALL                                         $19     
         39        ASSIGN                                                   !4, $19
   72    40        INIT_FCALL                                               'file_put_contents'
         41        SEND_VAR                                                 !0
         42        SEND_VAR                                                 !4
         43        DO_ICALL                                                 
   73    44      > RETURN                                                   null

End of function write_to_file

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.25 ms | 1402 KiB | 35 Q