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) ); } }

preferences:
31.58 ms | 402 KiB | 5 Q