3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { const PER_MONTH = 200000; /** * Get the number of working days in the current month. * * @return int */ private function getWorkingDaysThisMonth() { $working_days = 0; for ($i = 1; $i < date('t') + 1; $i++) { $thisDay = date('D', strtotime(date('Y-m-' . $i))); if (!($thisDay == 'Sun' || $thisDay == 'Sat')) { $working_days++; } } return $working_days; } /** * Get the number of records added to the site per second. * * @return float */ private function getRecordsPerSecond() { // Get the number of seconds in the current month // 9 is the number of working hours in one day (0830-1730). $seconds_current_month = $this->getWorkingDaysThisMonth() * 9 * 60 * 60; // Get the number of records per second $records_per_second = round(self::PER_MONTH / $seconds_current_month, 4); return $records_per_second; } /** * Get the number of rates added to the site to date. * * @param int $records_per_second The rate of records generated per second. * @return float|int */ private function getRatesToDate($records_per_second) { // Get the UNIX timestamp of the start of 2012-05-01 $start_month = strtotime('2012-05-01 00:00:00'); // Get the UNIX timestamp of the start of this month $start_of_current_month = strtotime(date('Y-m-01 00:00:00', time())); // First of current month // Set how many rates per month $counter = 0; // Work out where we are upto already while($start_month < $start_of_current_month) { // Add on historical months of rates $counter += self::PER_MONTH; $start_month = strtotime("+1 month", $start_month); } // Get the number of seconds that have passed in this month $seconds_elapsed_this_month = time() - $start_of_current_month; // Add on the remained of this month $counter += ceil($seconds_elapsed_this_month * $records_per_second); return $counter; } public function get() { $s = $this->getRecordsPerSecond(); return array( 'per_second' => $s, 'counter' => $this->getRatesToDate($s) ); } } var_dump(Foo::get());
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JKQvb
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   INIT_FCALL                                               'var_dump'
          1        INIT_STATIC_METHOD_CALL                                  'Foo', 'get'
          2        DO_FCALL                                      0  $0      
          3        SEND_VAR                                                 $0
          4        DO_ICALL                                                 
          5      > RETURN                                                   1

Class Foo:
Function getworkingdaysthismonth:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 47) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 22
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 29, Position 2 = 3
Branch analysis from position: 29
Branch analysis from position: 3
Branch analysis from position: 22
Branch analysis from position: 19
filename:       /in/JKQvb
function name:  getWorkingDaysThisMonth
number of ops:  31
compiled vars:  !0 = $working_days, !1 = $i, !2 = $thisDay
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ASSIGN                                                   !0, 0
   14     1        ASSIGN                                                   !1, 1
          2      > JMP                                                      ->23
   15     3    >   INIT_FCALL                                               'date'
          4        SEND_VAL                                                 'D'
          5        INIT_FCALL                                               'strtotime'
          6        INIT_FCALL                                               'date'
          7        CONCAT                                           ~5      'Y-m-', !1
          8        SEND_VAL                                                 ~5
          9        DO_ICALL                                         $6      
         10        SEND_VAR                                                 $6
         11        DO_ICALL                                         $7      
         12        SEND_VAR                                                 $7
         13        DO_ICALL                                         $8      
         14        ASSIGN                                                   !2, $8
   16    15        IS_EQUAL                                         ~10     !2, 'Sun'
         16      > JMPNZ_EX                                         ~10     ~10, ->19
         17    >   IS_EQUAL                                         ~11     !2, 'Sat'
         18        BOOL                                             ~10     ~11
         19    >   BOOL_NOT                                         ~12     ~10
         20      > JMPZ                                                     ~12, ->22
   17    21    >   PRE_INC                                                  !0
   14    22    >   PRE_INC                                                  !1
         23    >   INIT_FCALL                                               'date'
         24        SEND_VAL                                                 't'
         25        DO_ICALL                                         $15     
         26        ADD                                              ~16     $15, 1
         27        IS_SMALLER                                               !1, ~16
         28      > JMPNZ                                                    ~17, ->3
   21    29    > > RETURN                                                   !0
   22    30*     > RETURN                                                   null

End of function getworkingdaysthismonth

Function getrecordspersecond:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JKQvb
function name:  getRecordsPerSecond
number of ops:  14
compiled vars:  !0 = $seconds_current_month, !1 = $records_per_second
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_METHOD_CALL                                         'getWorkingDaysThisMonth'
          1        DO_FCALL                                      0  $2      
          2        MUL                                              ~3      $2, 9
          3        MUL                                              ~4      ~3, 60
          4        MUL                                              ~5      ~4, 60
          5        ASSIGN                                                   !0, ~5
   36     6        INIT_FCALL                                               'round'
          7        DIV                                              ~7      200000, !0
          8        SEND_VAL                                                 ~7
          9        SEND_VAL                                                 4
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
   38    12      > RETURN                                                   !1
   39    13*     > RETURN                                                   null

End of function getrecordspersecond

Function getratestodate:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 25, Position 2 = 17
Branch analysis from position: 25
Branch analysis from position: 17
filename:       /in/JKQvb
function name:  getRatesToDate
number of ops:  36
compiled vars:  !0 = $records_per_second, !1 = $start_month, !2 = $start_of_current_month, !3 = $counter, !4 = $seconds_elapsed_this_month
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   50     1        INIT_FCALL                                               'strtotime'
          2        SEND_VAL                                                 '2012-05-01+00%3A00%3A00'
          3        DO_ICALL                                         $5      
          4        ASSIGN                                                   !1, $5
   53     5        INIT_FCALL                                               'strtotime'
          6        INIT_FCALL                                               'date'
          7        SEND_VAL                                                 'Y-m-01+00%3A00%3A00'
          8        INIT_FCALL                                               'time'
          9        DO_ICALL                                         $7      
         10        SEND_VAR                                                 $7
         11        DO_ICALL                                         $8      
         12        SEND_VAR                                                 $8
         13        DO_ICALL                                         $9      
         14        ASSIGN                                                   !2, $9
   56    15        ASSIGN                                                   !3, 0
   59    16      > JMP                                                      ->23
   62    17    >   ASSIGN_OP                                     1          !3, 200000
   63    18        INIT_FCALL                                               'strtotime'
         19        SEND_VAL                                                 '%2B1+month'
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $13     
         22        ASSIGN                                                   !1, $13
   59    23    >   IS_SMALLER                                               !1, !2
         24      > JMPNZ                                                    ~15, ->17
   67    25    >   INIT_FCALL                                               'time'
         26        DO_ICALL                                         $16     
         27        SUB                                              ~17     $16, !2
         28        ASSIGN                                                   !4, ~17
   70    29        INIT_FCALL                                               'ceil'
         30        MUL                                              ~19     !4, !0
         31        SEND_VAL                                                 ~19
         32        DO_ICALL                                         $20     
         33        ASSIGN_OP                                     1          !3, $20
   72    34      > RETURN                                                   !3
   73    35*     > RETURN                                                   null

End of function getratestodate

Function get:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/JKQvb
function name:  get
number of ops:  10
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   79     0  E >   INIT_METHOD_CALL                                         'getRecordsPerSecond'
          1        DO_FCALL                                      0  $1      
          2        ASSIGN                                                   !0, $1
   83     3        INIT_ARRAY                                       ~3      !0, 'per_second'
   84     4        INIT_METHOD_CALL                                         'getRatesToDate'
          5        SEND_VAR                                                 !0
          6        DO_FCALL                                      0  $4      
          7        ADD_ARRAY_ELEMENT                                ~3      $4, 'counter'
          8      > RETURN                                                   ~3
   90     9*     > RETURN                                                   null

End of function get

End of class Foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.35 ms | 1404 KiB | 25 Q