1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Convert Execution time to Milliseconds

Discussion in 'PHP' started by Fiverscripts, Apr 11, 2016.

  1. #1
    I have coded something that reads the millisecond time value but i would also like to give the option to use the default php max execution time however its in seconds and not formatted to milliseconds:

    $max_time = ini_get('max_execution_time');
    PHP:
    That will get you the current set max execution time.. the only problem i have is its in seconds e.g 30 but i need it formatted as milliseconds.. anyone got a simple format/convert?
     
    Solved! View solution.
    Fiverscripts, Apr 11, 2016 IP
  2. #2
    After extensive research and some very phone calls I had to make to some very important people, I was able to narrow down the formula to convert seconds into millisecond as follows:

    
    <?php
    interface abstractImplementer
    {
        public function get_ratio();
    }
    
    abstract class abstractConverter
    {
        abstract protected function _set_ratio($constant);
        abstract public function get_ratio();
    
        public function printOut() {
            print $this->get_ratio() . "\n";
        }
    }
    
    class millisecondToSeconds extends abstractConverter implements abstractImplementer
    {
        /**
         * S <> MS ratio
         *
         * @var int
         */
        protected $_ratio = false;
    
        /**
         * Constructor
         */
        public function __construct($constant)
        {
            $this->_set_ratio($constant);
        }
    
        /**
         * Free memory usage
         */
        public function __destruct()
        {
            unset($this->_ratio);
        }
    
        /**
         * Set Ratio
         *
         * @var int $constant
         */
        protected function _set_ratio($constant)
        {
            $this->_ratio = $constant;
        }
    
        /**
         * Get Ratio
         *
         * return int
         */
        public function get_ratio()
        {
            return $this->_ratio;
        }
    
        /**
         * Convert
         *
         * @param int $seconds
         *
         * @return int
         */
        public function convert($seconds)
        {
            if (empty($seconds)) {
                throw new Exception('Invalid seconds to convert');
            }
    
            return $seconds * $this->get_ratio();
        }
    }
    
    define('RATIO_CONSTANT', 0b1111101000);
    $converter = new millisecondToSeconds(RATIO_CONSTANT);
    echo $converter->convert(30);
    
    PHP:
    Here is a live example/demo:
    http://sandbox.onlinephpfunctions.com/code/1c95dfdeface766071458d6cde558c6e1235509a

    I am not sure how dangerous it is to use this formula, I personally would never use it but be warned, only use it if you have pretty strong political connections.
     
    ThePHPMaster, Apr 11, 2016 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Uhm, ok... @ThePHPMaster, is that a ****ing joke, or are you actually serious with that crap? Much less is this even a serious honking quesition?!?

    It's milliseconds.... divide by 1000... since there's 1000 milliseconds to a second... you know, what that "milli" part MEANS?!?

    Sweet hey Zeus H mammary plowing Christmas, are you sure this wasn't supposed to be an April fools post?!? I find it incomprehensible that anyone with anything higher than a 4th grade education would even be asking this question!!!

    P.S. You cannot rely on most system timers returning ms accuracy, typically there's around 5ms of jitter and 30ms granularity in PHP... which is why any result less than around a third of a second is unreliable rubbish and can't be used for an accurate measurement of anything.
     
    deathshadow, Apr 12, 2016 IP
  4. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #4
    :)
    
    $max_milli_time = intval(ini_get('max_execution_time')) * 1000;
    print $max_milli_time;
    
    Code (markup):
     
    Vooler, May 12, 2016 IP