Example #1
0
 public function testFormatShort()
 {
     $this->assertEquals('4ms', milliseconds(4)->format('ms'));
     $this->assertEquals('1s', milliseconds(1000)->format('s'));
     $this->assertEquals('4s', seconds(4)->format('s'));
     $this->assertEquals('4m', minutes(4)->format('m'));
     $this->assertEquals('32h', hours(32)->format('h'));
     $this->assertEquals('4d', days(4)->format('d'));
     $this->assertEquals('1w', days(7)->format('w'));
     $this->assertEquals('3mo', weeks(13)->format('mo'));
     $this->assertEquals('1y', months(12)->format('y'));
 }
Example #2
0
    <ul class="feed">
<?php 
foreach ($items as $item) {
    ?>
      <li>
        <h2><a href="<?php 
    echo $item['link'];
    ?>
"><span><?php 
    echo SmartyPants($item['title']);
    ?>
</span></a></h2>
        <p><?php 
    echo $item['description'];
    ?>
</p>
        <p class="date"><?php 
    echo date('F j', $item['published_at']);
    ?>
</p>
      </li>
<?php 
}
?>
    </ul>
  </body>
</html><!-- <?php 
echo milliseconds() - $time . "ms";
?>
 -->
Example #3
0
File: api.php Project: prggmr/xpspl
/**
 * Registers a standard output mechanism for test results.
 *
 * @return  void
 */
function generate_output()
{
    // enable the event history
    xp_set_signal_history(true);
    // Startup
    xp_on_start(function () {
        if (XPSPL_DEBUG) {
            logger(XPSPL_LOG)->info('Unittest begin');
        }
        define('UNITTEST_START_TIME', milliseconds());
    });
    // Shutdown
    xp_on_shutdown(function () {
        if (XPSPL_DEBUG) {
            logger(XPSPL_LOG)->info('Unittest end');
        }
        define('UNITTEST_END_TIME', milliseconds());
        $tests = 0;
        $pass = 0;
        $fail = 0;
        $skip = 0;
        $output = Output::instance();
        $tests_run = [];
        foreach (xp_signal_history() as $_node) {
            if ($_node[0] instanceof SIG_Test) {
                // suites
                $tests++;
                $tests_run[] = $_node[0];
                $failures = [];
                // Get passedXPSPL
                foreach ($_node[0]->get_assertion_results() as $_assertion) {
                    if ($_assertion[0] === true) {
                        $pass++;
                    } elseif ($_assertion[0] === null) {
                        $skip++;
                    } else {
                        $fail++;
                        $failures[] = $_assertion;
                    }
                }
                if (count($failures) != 0) {
                    $output->send_linebreak(Output::ERROR);
                    foreach ($failures as $_failure) {
                        $output->send("FAILURE", Output::ERROR);
                        $output->send("ASSERTION : " . $_failure[1], Output::ERROR, true);
                        $output->send("MESSAGE : " . $_failure[0], Output::ERROR, true);
                        $output->send(sprintf('ARGUMENTS : %s', $output->variable($_failure[2])), Output::ERROR, true);
                        $trace = $_failure[3][1];
                        $output->send("FILE : " . $trace["file"], Output::ERROR, true);
                        $output->send("LINE : " . $trace["line"], Output::ERROR);
                        $output->send_linebreak(Output::ERROR);
                    }
                }
            }
        }
        $size = function ($size) {
            /**
             * This was authored by another individual by whom i don't know
             */
            $filesizename = array(" Bytes", "KB", "MB", "GB", "TB", "PB", " EB", "ZB", "YB");
            return $size ? round($size / pow(1024, $i = floor(log($size, 1024))), 2) . $filesizename[$i] : '0 Bytes';
        };
        $output->send_linebreak();
        $output->send(sprintf("Ran %s tests in %sms and used %s memory", $tests, UNITTEST_END_TIME - UNITTEST_START_TIME, $size(memory_get_peak_usage())), Output::SYSTEM, true);
        $output->send(sprintf("%s Assertions: %s Passed, %s Failed, %s Skipped", $pass + $fail + $skip, $pass, $fail, $skip), Output::SYSTEM, true);
    });
}
Example #4
0
<?php

xp_import('time');
$precision = 10;
$signal = new \time\SIG_Awake($precision, TIME_MILLISECONDS);
$signal->time = milliseconds();
$precision_timing = [];
$function = xp_exhaust(100, function ($signal) use($precision, &$precision_timing) {
    $timing = intval(floatval(milliseconds() - $signal->time)) - $precision;
    echo $timing . PHP_EOL;
    // if ($timing > 100000) {
    //     // Second change
    //     $timing = 0;
    // }
    $precision_timing[] = [$timing, 0];
    $signal->time = milliseconds();
});
xp_signal($signal, $function);
xp_on_shutdown(function () use(&$precision_timing) {
    array_shift($precision_timing);
    $results = ['msPrecision' => $precision_timing];
    ob_start();
    include dirname(realpath(__FILE__)) . '/chart.php';
    $data = ob_get_contents();
    ob_end_clean();
    file_put_contents('millisecond_precision.html', $data);
    echo "Performance chart in millisecond_precision.html" . PHP_EOL;
});
 protected function makeSoapCall($operation, $parameter)
 {
     if ($this->userequest) {
         // use request level credentials, add passport as a SOAP header
         $this->addHeader("passport", $this->passport);
         // SoapClient, even with keep-alive set to false, keeps sending the JSESSIONID cookie back to the server on subsequent requests. Unsetting the cookie to prevent this.
         $this->client->__setCookie("JSESSIONID");
     } else {
         $this->clearHeader("passport");
     }
     $response = $this->client->__soapCall($operation, array($parameter), NULL, $this->soapHeaders);
     if (file_exists(dirname(__FILE__) . '/nslog')) {
         // log the request and response into the nslog directory. Code taken from PHP toolkit
         // REQUEST
         $req = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-request.xml";
         $Handle = fopen($req, 'w');
         $Data = $this->client->__getLastRequest();
         $xml_string = $this->prepSoapStringForLog($Data);
         fwrite($Handle, $xml_string);
         fclose($Handle);
         // RESPONSE
         $resp = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-response.xml";
         $Handle = fopen($resp, 'w');
         $Data = $this->client->__getLastResponse();
         $xml_string = $this->prepSoapStringForLog($Data);
         fwrite($Handle, $xml_string);
         fclose($Handle);
     }
     return $response;
 }
Example #6
0
 protected function makeSoapCall($operation, $parameter)
 {
     if ($this->userequest) {
         // use request level credentials, add passport as a SOAP header
         $this->addHeader("passport", $this->passport);
         // SoapClient, even with keep-alive set to false, keeps sending the JSESSIONID cookie back to the server on subsequent requests. Unsetting the cookie to prevent this.
         $this->client->__setCookie("JSESSIONID");
     } else {
         $this->clearHeader("passport");
     }
     $response = $this->client->__soapCall($operation, array($parameter), NULL, $this->soapHeaders);
     if (file_exists(dirname(__FILE__) . '/nslog')) {
         // log the request and response into the nslog directory. Code taken from PHP toolkit
         // REQUEST
         $req = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-request.xml";
         $Handle = fopen($req, 'w');
         $Data = $this->client->__getLastRequest();
         $Data = cleanUpNamespaces($Data);
         $xml = simplexml_load_string($Data, 'SimpleXMLElement', LIBXML_NOCDATA);
         $passwordFields = $xml->xpath("//password | //password2 | //currentPassword | //newPassword | //newPassword2 | //ccNumber | //ccSecurityCode | //socialSecurityNumber");
         foreach ($passwordFields as &$pwdField) {
             (string) ($pwdField[0] = "[Content Removed for Security Reasons]");
         }
         $stringCustomFields = $xml->xpath("//customField[@xsitype='StringCustomFieldRef']");
         foreach ($stringCustomFields as $field) {
             (string) ($field->value = "[Content Removed for Security Reasons]");
         }
         $xml_string = str_replace('xsitype', 'xsi:type', $xml->asXML());
         fwrite($Handle, $xml_string);
         fclose($Handle);
         // RESPONSE
         $resp = dirname(__FILE__) . '/nslog' . "/" . date("Ymd.His") . "." . milliseconds() . "-" . $operation . "-response.xml";
         $Handle = fopen($resp, 'w');
         $Data = $this->client->__getLastResponse();
         fwrite($Handle, $Data);
         fclose($Handle);
     }
     return $response;
 }
Example #7
0
function millisecond($numberOf)
{
    return milliseconds($numberOf);
}
Example #8
0
 /**
  * Determines if the time to idle until has passed.
  *
  * @return  boolean
  */
 public function has_time_passed()
 {
     switch ($this->_instruction) {
         case TIME_SECONDS:
             return $this->_stop_time <= time();
             break;
         case TIME_MILLISECONDS:
             return $this->_stop_time <= milliseconds();
             break;
         case TIME_MICROSECONDS:
             return $this->_stop_time <= microtime(true);
             break;
     }
 }
Example #9
0
<?php

error_reporting(0);
require 'helpers.php';
$time = milliseconds();
# Load our items
$path = dirname(__FILE__);
$items = yaml_decode_file("{$path}/items.yml");
# Now sort them, newest to oldest...
$items = array_reverse(array_sort_by_key($items, 'published_at'));
# ...and skip forward-dated items
$items = array_reject($items, '$item[\'published_at\'] <= ' . time());