3v4l.org

run code in 300+ PHP versions simultaneously
<?php set_time_limit(0); ### Helpers: function print_mem() { /* Currently used memory */ $mem_usage = memory_get_usage(); /* Peak memory usage */ $mem_peak = memory_get_peak_usage(); echo " " . 'The script is now using: ' . $mem_usage . " B of memory.\n"; echo " " . 'The script is now using: ' . round($mem_usage / 1024) . " KB of memory.\n"; echo " " . "Peak usage: " . round($mem_peak / 1024) . " KB of memory.\n"; } function get_formatted_microtime($time) { $to_format = DateTime::createFromFormat('U.u', sprintf("%.6F", $time)); $formatted = $to_format->format("Y-m-d H:i:s.u"); return $formatted; } ### Load Config: $time_start = microtime(true); // Loading configuration $config = parse_ini_file("config.ini", true); $time_end = microtime(true); $time = ($time_end - $time_start) * 1000; ### Merge CLI parameters into $_GET: if (isset($config['common-parameters'])) { foreach($config['common-parameters'] as $key => $value) { if (!isset($_GET[$key])) { $_GET[$key] = $value; } } } if (!empty($argv)) { parse_str(implode('&', array_slice($argv, 1)), $cli_arguments); $_GET = array_merge($_GET, $cli_arguments); } ### if (empty($argv)) { echo "<pre>\n"; } ### Connect to the database: $iteration = 0; $number_of_iterations = (int) $_GET['number_of_iterations']; while (true) { $iteration++; ### Actual Connection Time: $connection_attempt_start = microtime(true); $connection_attempt_start_formatted = get_formatted_microtime($connection_attempt_start); $was_connection_successful = false; try { echo "Before PDO Connection Attempt:\n"; print_mem(); // Creating MySQL Connection: $port = (int) $config['database']['port']; $dsn = "mysql:host={$config['database']['host']};dbname={$config['database']['database']};port={$port}"; $options = []; if ((bool) $config['database']['use_ssl']) { $options[PDO::MYSQL_ATTR_SSL_CA] = $config['ca_root_path']; } $pdo = new PDO($dsn, $config['database']['username'], $config['database']['password'], $options); $was_connection_successful = true; } catch (PDOException $e) { echo $e->code . ' ' . $e->message . "\n"; $was_connection_successful = false; } echo "After PDO Connection Attempt:\n"; print_mem(); $connection_attempt_end = microtime(true); $connection_attempt_end_formatted = get_formatted_microtime($connection_attempt_end); $connection_time = ($connection_attempt_end - $connection_attempt_start) * 1000; if ((bool)$_GET['show_output']) { if ($was_connection_successful) { echo "{$iteration}. Connected to database ({$config['database']['host']}) in $connection_time milliseconds.\n"; } else { echo "{$iteration}. Connection attempt to database ({$config['database']['host']}) failed after $connection_time milliseconds. Sleeping for 3 seconds.\n"; sleep(3); } } unset($pdo); if ($number_of_iterations !== 0 && $iteration >= $number_of_iterations) { break; } if (isset($_GET['iteration_delay']) && $_GET['iteration_delay'] > 0) { sleep((int) $_GET['iteration_delay']); } echo "Iteration finished: \n"; print_mem(); } if (empty($argv)) { echo "\n</pre>"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 34
Branch analysis from position: 21
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 33
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 33
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 32
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 56
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 58, Position 2 = 59
Branch analysis from position: 58
1 jumps found. (Code = 42) Position 1 = 190
Branch analysis from position: 190
2 jumps found. (Code = 44) Position 1 = 191, Position 2 = 65
Branch analysis from position: 191
2 jumps found. (Code = 43) Position 1 = 193, Position 2 = 194
Branch analysis from position: 193
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 194
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 98, Position 2 = 102
Branch analysis from position: 98
1 jumps found. (Code = 42) Position 1 = 125
Branch analysis from position: 125
2 jumps found. (Code = 43) Position 1 = 143, Position 2 = 166
Branch analysis from position: 143
2 jumps found. (Code = 43) Position 1 = 144, Position 2 = 154
Branch analysis from position: 144
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
2 jumps found. (Code = 46) Position 1 = 169, Position 2 = 171
Branch analysis from position: 169
2 jumps found. (Code = 43) Position 1 = 172, Position 2 = 173
Branch analysis from position: 172
1 jumps found. (Code = 42) Position 1 = 191
Branch analysis from position: 191
Branch analysis from position: 173
2 jumps found. (Code = 46) Position 1 = 176, Position 2 = 180
Branch analysis from position: 176
2 jumps found. (Code = 43) Position 1 = 181, Position 2 = 187
Branch analysis from position: 181
2 jumps found. (Code = 44) Position 1 = 191, Position 2 = 65
Branch analysis from position: 191
Branch analysis from position: 65
Branch analysis from position: 187
Branch analysis from position: 180
Branch analysis from position: 171
Branch analysis from position: 154
2 jumps found. (Code = 46) Position 1 = 169, Position 2 = 171
Branch analysis from position: 169
Branch analysis from position: 171
Branch analysis from position: 166
Branch analysis from position: 102
Branch analysis from position: 59
Branch analysis from position: 56
Branch analysis from position: 33
Branch analysis from position: 34
Found catch point at position: 117
Branch analysis from position: 117
2 jumps found. (Code = 107) Position 1 = 118, Position 2 = -2
Branch analysis from position: 118
2 jumps found. (Code = 43) Position 1 = 143, Position 2 = 166
Branch analysis from position: 143
Branch analysis from position: 166
filename:       /in/BOnq5
function name:  (null)
number of ops:  195
compiled vars:  !0 = $time_start, !1 = $config, !2 = $time_end, !3 = $time, !4 = $value, !5 = $key, !6 = $argv, !7 = $cli_arguments, !8 = $iteration, !9 = $number_of_iterations, !10 = $connection_attempt_start, !11 = $connection_attempt_start_formatted, !12 = $was_connection_successful, !13 = $port, !14 = $dsn, !15 = $options, !16 = $pdo, !17 = $e, !18 = $connection_attempt_end, !19 = $connection_attempt_end_formatted, !20 = $connection_time
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                               'set_time_limit'
          1        SEND_VAL                                                 0
          2        DO_ICALL                                                 
   30     3        INIT_FCALL                                               'microtime'
          4        SEND_VAL                                                 <true>
          5        DO_ICALL                                         $22     
          6        ASSIGN                                                   !0, $22
   33     7        INIT_FCALL                                               'parse_ini_file'
          8        SEND_VAL                                                 'config.ini'
          9        SEND_VAL                                                 <true>
         10        DO_ICALL                                         $24     
         11        ASSIGN                                                   !1, $24
   35    12        INIT_FCALL                                               'microtime'
         13        SEND_VAL                                                 <true>
         14        DO_ICALL                                         $26     
         15        ASSIGN                                                   !2, $26
   36    16        SUB                                              ~28     !2, !0
         17        MUL                                              ~29     ~28, 1000
         18        ASSIGN                                                   !3, ~29
   40    19        ISSET_ISEMPTY_DIM_OBJ                         0          !1, 'common-parameters'
         20      > JMPZ                                                     ~31, ->34
   41    21    >   FETCH_DIM_R                                      ~32     !1, 'common-parameters'
         22      > FE_RESET_R                                       $33     ~32, ->33
         23    > > FE_FETCH_R                                       ~34     $33, !4, ->33
         24    >   ASSIGN                                                   !5, ~34
   42    25        FETCH_IS                                         ~36     '_GET'
         26        ISSET_ISEMPTY_DIM_OBJ                         0  ~37     ~36, !5
         27        BOOL_NOT                                         ~38     ~37
         28      > JMPZ                                                     ~38, ->32
   43    29    >   FETCH_W                      global              $39     '_GET'
         30        ASSIGN_DIM                                               $39, !5
         31        OP_DATA                                                  !4
   41    32    > > JMP                                                      ->23
         33    >   FE_FREE                                                  $33
   48    34    >   ISSET_ISEMPTY_CV                                 ~41     !6
         35        BOOL_NOT                                         ~42     ~41
         36      > JMPZ                                                     ~42, ->56
   49    37    >   INIT_FCALL                                               'parse_str'
         38        INIT_FCALL                                               'implode'
         39        SEND_VAL                                                 '%26'
         40        INIT_FCALL                                               'array_slice'
         41        SEND_VAR                                                 !6
         42        SEND_VAL                                                 1
         43        DO_ICALL                                         $43     
         44        SEND_VAR                                                 $43
         45        DO_ICALL                                         $44     
         46        SEND_VAR                                                 $44
         47        SEND_REF                                                 !7
         48        DO_ICALL                                                 
   50    49        INIT_FCALL                                               'array_merge'
         50        FETCH_R                      global              ~47     '_GET'
         51        SEND_VAL                                                 ~47
         52        SEND_VAR                                                 !7
         53        DO_ICALL                                         $48     
         54        FETCH_W                      global              $46     '_GET'
         55        ASSIGN                                                   $46, $48
   55    56    >   ISSET_ISEMPTY_CV                                         !6
         57      > JMPZ                                                     ~50, ->59
   56    58    >   ECHO                                                     '%3Cpre%3E%0A'
   61    59    >   ASSIGN                                                   !8, 0
   62    60        FETCH_R                      global              ~52     '_GET'
         61        FETCH_DIM_R                                      ~53     ~52, 'number_of_iterations'
         62        CAST                                          4  ~54     ~53
         63        ASSIGN                                                   !9, ~54
   64    64      > JMP                                                      ->190
   66    65    >   PRE_INC                                                  !8
   70    66        INIT_FCALL                                               'microtime'
         67        SEND_VAL                                                 <true>
         68        DO_ICALL                                         $57     
         69        ASSIGN                                                   !10, $57
   71    70        INIT_FCALL                                               'get_formatted_microtime'
         71        SEND_VAR                                                 !10
         72        DO_FCALL                                      0  $59     
         73        ASSIGN                                                   !11, $59
   73    74        ASSIGN                                                   !12, <false>
   76    75        ECHO                                                     'Before+PDO+Connection+Attempt%3A%0A'
   77    76        INIT_FCALL                                               'print_mem'
         77        DO_FCALL                                      0          
   79    78        FETCH_DIM_R                                      ~63     !1, 'database'
         79        FETCH_DIM_R                                      ~64     ~63, 'port'
         80        CAST                                          4  ~65     ~64
         81        ASSIGN                                                   !13, ~65
   80    82        ROPE_INIT                                     6  ~72     'mysql%3Ahost%3D'
         83        FETCH_DIM_R                                      ~67     !1, 'database'
         84        FETCH_DIM_R                                      ~68     ~67, 'host'
         85        ROPE_ADD                                      1  ~72     ~72, ~68
         86        ROPE_ADD                                      2  ~72     ~72, '%3Bdbname%3D'
         87        FETCH_DIM_R                                      ~69     !1, 'database'
         88        FETCH_DIM_R                                      ~70     ~69, 'database'
         89        ROPE_ADD                                      3  ~72     ~72, ~70
         90        ROPE_ADD                                      4  ~72     ~72, '%3Bport%3D'
         91        ROPE_END                                      5  ~71     ~72, !13
         92        ASSIGN                                                   !14, ~71
   82    93        ASSIGN                                                   !15, <array>
   83    94        FETCH_DIM_R                                      ~77     !1, 'database'
         95        FETCH_DIM_R                                      ~78     ~77, 'use_ssl'
         96        BOOL                                             ~79     ~78
         97      > JMPZ                                                     ~79, ->102
   84    98    >   FETCH_CLASS_CONSTANT                             ~80     'PDO', 'MYSQL_ATTR_SSL_CA'
         99        FETCH_DIM_R                                      ~82     !1, 'ca_root_path'
        100        ASSIGN_DIM                                               !15, ~80
        101        OP_DATA                                                  ~82
   87   102    >   NEW                                              $83     'PDO'
        103        SEND_VAR_EX                                              !14
        104        CHECK_FUNC_ARG                                           
        105        FETCH_DIM_FUNC_ARG                               $84     !1, 'database'
        106        FETCH_DIM_FUNC_ARG                               $85     $84, 'username'
        107        SEND_FUNC_ARG                                            $85
        108        CHECK_FUNC_ARG                                           
        109        FETCH_DIM_FUNC_ARG                               $86     !1, 'database'
        110        FETCH_DIM_FUNC_ARG                               $87     $86, 'password'
        111        SEND_FUNC_ARG                                            $87
        112        SEND_VAR_EX                                              !15
        113        DO_FCALL                                      0          
        114        ASSIGN                                                   !16, $83
   89   115        ASSIGN                                                   !12, <true>
        116      > JMP                                                      ->125
   91   117  E > > CATCH                                       last         'PDOException'
   92   118    >   FETCH_OBJ_R                                      ~91     !17, 'code'
        119        CONCAT                                           ~92     ~91, '+'
        120        FETCH_OBJ_R                                      ~93     !17, 'message'
        121        CONCAT                                           ~94     ~92, ~93
        122        CONCAT                                           ~95     ~94, '%0A'
        123        ECHO                                                     ~95
   93   124        ASSIGN                                                   !12, <false>
   96   125    >   ECHO                                                     'After+PDO+Connection+Attempt%3A%0A'
   97   126        INIT_FCALL                                               'print_mem'
        127        DO_FCALL                                      0          
   99   128        INIT_FCALL                                               'microtime'
        129        SEND_VAL                                                 <true>
        130        DO_ICALL                                         $98     
        131        ASSIGN                                                   !18, $98
  100   132        INIT_FCALL                                               'get_formatted_microtime'
        133        SEND_VAR                                                 !18
        134        DO_FCALL                                      0  $100    
        135        ASSIGN                                                   !19, $100
  101   136        SUB                                              ~102    !18, !10
        137        MUL                                              ~103    ~102, 1000
        138        ASSIGN                                                   !20, ~103
  104   139        FETCH_R                      global              ~105    '_GET'
        140        FETCH_DIM_R                                      ~106    ~105, 'show_output'
        141        BOOL                                             ~107    ~106
        142      > JMPZ                                                     ~107, ->166
  105   143    > > JMPZ                                                     !12, ->154
  106   144    >   ROPE_INIT                                     6  ~111    !8
        145        ROPE_ADD                                      1  ~111    ~111, '.+Connected+to+database+%28'
        146        FETCH_DIM_R                                      ~108    !1, 'database'
        147        FETCH_DIM_R                                      ~109    ~108, 'host'
        148        ROPE_ADD                                      2  ~111    ~111, ~109
        149        ROPE_ADD                                      3  ~111    ~111, '%29+in+'
        150        ROPE_ADD                                      4  ~111    ~111, !20
        151        ROPE_END                                      5  ~110    ~111, '+milliseconds.%0A'
        152        ECHO                                                     ~110
  105   153      > JMP                                                      ->166
  108   154    >   ROPE_INIT                                     6  ~117    !8
        155        ROPE_ADD                                      1  ~117    ~117, '.+Connection+attempt+to+database+%28'
        156        FETCH_DIM_R                                      ~114    !1, 'database'
        157        FETCH_DIM_R                                      ~115    ~114, 'host'
        158        ROPE_ADD                                      2  ~117    ~117, ~115
        159        ROPE_ADD                                      3  ~117    ~117, '%29+failed+after+'
        160        ROPE_ADD                                      4  ~117    ~117, !20
        161        ROPE_END                                      5  ~116    ~117, '+milliseconds.+Sleeping+for+3+seconds.%0A'
        162        ECHO                                                     ~116
  109   163        INIT_FCALL                                               'sleep'
        164        SEND_VAL                                                 3
        165        DO_ICALL                                                 
  113   166    >   UNSET_CV                                                 !16
  115   167        IS_NOT_IDENTICAL                                 ~121    !9, 0
        168      > JMPZ_EX                                          ~121    ~121, ->171
        169    >   IS_SMALLER_OR_EQUAL                              ~122    !9, !8
        170        BOOL                                             ~121    ~122
        171    > > JMPZ                                                     ~121, ->173
  116   172    > > JMP                                                      ->191
  119   173    >   FETCH_IS                                         ~123    '_GET'
        174        ISSET_ISEMPTY_DIM_OBJ                         0  ~124    ~123, 'iteration_delay'
        175      > JMPZ_EX                                          ~124    ~124, ->180
        176    >   FETCH_R                      global              ~125    '_GET'
        177        FETCH_DIM_R                                      ~126    ~125, 'iteration_delay'
        178        IS_SMALLER                                       ~127    0, ~126
        179        BOOL                                             ~124    ~127
        180    > > JMPZ                                                     ~124, ->187
  120   181    >   INIT_FCALL                                               'sleep'
        182        FETCH_R                      global              ~128    '_GET'
        183        FETCH_DIM_R                                      ~129    ~128, 'iteration_delay'
        184        CAST                                          4  ~130    ~129
        185        SEND_VAL                                                 ~130
        186        DO_ICALL                                                 
  123   187    >   ECHO                                                     'Iteration+finished%3A+%0A'
  124   188        INIT_FCALL                                               'print_mem'
        189        DO_FCALL                                      0          
   64   190    > > JMPNZ                                                    <true>, ->65
  127   191    >   ISSET_ISEMPTY_CV                                         !6
        192      > JMPZ                                                     ~133, ->194
  128   193    >   ECHO                                                     '%0A%3C%2Fpre%3E'
  129   194    > > RETURN                                                   1

Function print_mem:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BOnq5
function name:  print_mem
number of ops:  24
compiled vars:  !0 = $mem_usage, !1 = $mem_peak
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   INIT_FCALL                                               'memory_get_usage'
          1        DO_ICALL                                         $2      
          2        ASSIGN                                                   !0, $2
   13     3        INIT_FCALL                                               'memory_get_peak_usage'
          4        DO_ICALL                                         $4      
          5        ASSIGN                                                   !1, $4
   15     6        CONCAT                                           ~6      '++++The+script+is+now+using%3A+', !0
          7        CONCAT                                           ~7      ~6, '+B+of+memory.%0A'
          8        ECHO                                                     ~7
   16     9        INIT_FCALL                                               'round'
         10        DIV                                              ~8      !0, 1024
         11        SEND_VAL                                                 ~8
         12        DO_ICALL                                         $9      
         13        CONCAT                                           ~10     '++++The+script+is+now+using%3A+', $9
         14        CONCAT                                           ~11     ~10, '+KB+of+memory.%0A'
         15        ECHO                                                     ~11
   17    16        INIT_FCALL                                               'round'
         17        DIV                                              ~12     !1, 1024
         18        SEND_VAL                                                 ~12
         19        DO_ICALL                                         $13     
         20        CONCAT                                           ~14     '++++Peak+usage%3A+', $13
         21        CONCAT                                           ~15     ~14, '+KB+of+memory.%0A'
         22        ECHO                                                     ~15
   18    23      > RETURN                                                   null

End of function print_mem

Function get_formatted_microtime:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BOnq5
function name:  get_formatted_microtime
number of ops:  16
compiled vars:  !0 = $time, !1 = $to_format, !2 = $formatted
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   RECV                                             !0      
   21     1        INIT_STATIC_METHOD_CALL                                  'DateTime', 'createFromFormat'
          2        SEND_VAL                                                 'U.u'
          3        INIT_FCALL                                               'sprintf'
          4        SEND_VAL                                                 '%25.6F'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $3      
          7        SEND_VAR                                                 $3
          8        DO_FCALL                                      0  $4      
          9        ASSIGN                                                   !1, $4
   23    10        INIT_METHOD_CALL                                         !1, 'format'
         11        SEND_VAL_EX                                              'Y-m-d+H%3Ai%3As.u'
         12        DO_FCALL                                      0  $6      
         13        ASSIGN                                                   !2, $6
   25    14      > RETURN                                                   !2
   26    15*     > RETURN                                                   null

End of function get_formatted_microtime

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.12 ms | 1050 KiB | 30 Q