コード例 #1
3
ファイル: Bcrypt.php プロジェクト: vkaran101/sase
 private function getRandomBytes($count)
 {
     $bytes = '';
     if (function_exists('openssl_random_pseudo_bytes') && strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') {
         // OpenSSL slow on Win
         $bytes = openssl_random_pseudo_bytes($count);
     }
     if ($bytes === '' && @is_readable('/dev/urandom') && ($hRand = @fopen('/dev/urandom', 'rb')) !== FALSE) {
         $bytes = fread($hRand, $count);
         fclose($hRand);
     }
     if (strlen($bytes) < $count) {
         $bytes = '';
         if ($this->randomState === null) {
             $this->randomState = microtime();
             if (function_exists('getmypid')) {
                 $this->randomState .= getmypid();
             }
         }
         for ($i = 0; $i < $count; $i += 16) {
             $this->randomState = md5(microtime() . $this->randomState);
             if (PHP_VERSION >= '5') {
                 $bytes .= md5($this->randomState, true);
             } else {
                 $bytes .= pack('H*', md5($this->randomState));
             }
         }
         $bytes = substr($bytes, 0, $count);
     }
     return $bytes;
 }
コード例 #2
1
ファイル: fortune.php プロジェクト: pombredanne/tuleap
 function quoteFromDir($dir)
 {
     $amount = 0;
     $index = 0;
     if ($handle = opendir($dir)) {
         while (false !== ($file = readdir($handle))) {
             if (strpos($file, ".dat") != false) {
                 $len = strlen($file);
                 if (substr($file, $len - 4) == ".dat") {
                     $number = $this->getNumberOfQuotes($dir . "/" . $file);
                     $amount += $number;
                     $quotes[$index] = $amount;
                     $files[$index] = $file;
                     $index++;
                 }
             }
         }
         srand((double) microtime() * 1000000);
         $index = rand(0, $amount);
         $i = 0;
         while ($quotes[$i] < $index) {
             $i++;
         }
         return $this->getRandomQuote($dir . "/" . $files[$i]);
     }
     return -1;
 }
コード例 #3
1
 /**
  * @param $phone
  * @param $code
  * @return bool
  * send sms to register&runner phone
  */
 private function smsSend($phone, $code)
 {
     $account = "mt6724";
     $password = "******";
     $time = microtime();
     $time = explode(" ", $time);
     $time = $time[1] + $time[0];
     $time = number_format($time * 1000, 0, ".", "");
     $timestamp = $time;
     $access_token = md5($timestamp . $password);
     $receive = $phone;
     $smscontent = "你的验证码为{$code},有效期10分钟";
     $str = "account={$account}&timestamp={$timestamp}&access_token={$access_token}&receiver={$receive}&smscontent={$smscontent}&extcode=0";
     $url = "http://121.42.11.93:8001/interface/sendSms";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 1);
     // post数据
     curl_setopt($ch, CURLOPT_POST, 1);
     // post的变量
     curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
     $output = curl_exec($ch);
     curl_close($ch);
     $res = json_decode($output, TRUE);
     if ($res['res_code'] == '0') {
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: eventlogger.php プロジェクト: kenwi/core
 public function end($id)
 {
     if (isset($this->events[$id])) {
         $timing = $this->events[$id];
         $timing->end(microtime(true));
     }
 }
コード例 #5
0
ファイル: TestCase.php プロジェクト: stage1/yuhao
 protected function getTmpDir()
 {
     $dir = sys_get_temp_dir() . '/' . substr(md5(microtime()), 0, 8);
     $fs = new Filesystem();
     $fs->mkdir($dir);
     return $dir;
 }
コード例 #6
0
 function randNumber($len = 6, $start = false, $end = false)
 {
     mt_srand((double) microtime() * 1000000);
     $start = !$len && $start ? $start : str_pad(1, $len, "0", STR_PAD_RIGHT);
     $end = !$len && $end ? $end : str_pad(9, $len, "9", STR_PAD_RIGHT);
     return mt_rand($start, $end);
 }
コード例 #7
0
 public function random_chars($len = 0)
 {
     if ($len == 0) {
         $len = rand(5, 20);
     }
     return substr(md5(microtime()), $len);
 }
コード例 #8
0
ファイル: Debug.php プロジェクト: avatar382/fablab_site
 /**
  * Measure time between two events
  *
  * First call should be to $key = Debug::timer() with no params, or provide your own key that's not already been used
  * Second call should pass the key given by the first call to get the time elapsed, i.e. $time = Debug::timer($key).
  * Note that you may make multiple calls back to Debug::timer() with the same key and it will continue returning the 
  * elapsed time since the original call. If you want to reset or remove the timer, call removeTimer or resetTimer.
  *
  * @param string $key 
  * 	Leave blank to start timer. 
  *	Specify existing key (string) to return timer. 
  *	Specify new made up key to start a named timer. 
  * @param bool $reset If the timer already exists, it will be reset when this is true. 
  * @return string|int
  *
  */
 public static function timer($key = '', $reset = false)
 {
     // returns number of seconds elapsed since first call
     if ($reset && $key) {
         self::removeTimer($key);
     }
     if (!$key || !isset(self::$timers[$key])) {
         // start new timer
         preg_match('/(\\.[0-9]+) ([0-9]+)/', microtime(), $time);
         $startTime = doubleval($time[1]) + doubleval($time[2]);
         if (!$key) {
             $key = $startTime;
             while (isset(self::$timers[$key])) {
                 $key .= ".";
             }
         }
         self::$timers[$key] = $startTime;
         $value = $key;
     } else {
         // return timer
         preg_match('/(\\.[0-9]*) ([0-9]*)/', microtime(), $time);
         $endTime = doubleval($time[1]) + doubleval($time[2]);
         $startTime = self::$timers[$key];
         $runTime = number_format($endTime - $startTime, 4);
         $value = $runTime;
     }
     return $value;
 }
コード例 #9
0
ファイル: Client.php プロジェクト: audriusb/elastic-benchmark
 public function execute(Request $request, $count, OutputInterface $out)
 {
     $client = new \Elasticsearch\Client(['hosts' => [$request->getHost()]]);
     $response = new Response();
     if ($this->clearCache) {
         $this->clearCache($client, $out);
     }
     $helper = new ProgressHelper();
     $helper->start($out, $count);
     $start = microtime(true);
     for ($i = 0; $i < $count; $i++) {
         try {
             $response->addSuccess($client->search($request->getParameters()));
         } catch (\Exception $ex) {
             $response->addFailure();
             var_dump($ex->getMessage());
             exit;
         }
         $helper->advance();
     }
     $helper->finish();
     $response->setExternalTime(microtime(true) - $start);
     try {
         $response->setStats($client->indices()->stats([['index' => $request->getIndex()], 'groups' => [$request->getStatId()]]));
     } catch (\Exception $ex) {
         // nothing to do here
     }
     return $response;
 }
コード例 #10
0
ファイル: ProgressBar.php プロジェクト: kehet/php-cli-utils
 /**
  * Updates bar by printing \r and new bar
  *
  * @param $progress Current value of progress between 0 and value given on constructor
  */
 public function update($progress)
 {
     $this->_times[] = microtime(true);
     $done = $progress == 0 ? 0 : round($progress / $this->_max * $this->_maxLength);
     $left = round((1 - $progress / $this->_max) * $this->_maxLength);
     // current/max
     $output = ' ' . sprintf('%' . strlen($this->_max) . 's/%s', $progress, $this->_max) . ' ';
     // progressbar
     $output .= '[' . str_repeat('=', $done != 0 ? $done - 1 : $done) . ($done > 0 ? '>' : '') . str_repeat('-', $left) . ']';
     // percent
     $output .= ' ' . sprintf('%6.2f', round($progress / $this->_max * 100, 2)) . "%";
     // eta
     // using http://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average
     // averageSpeed = SMOOTHING_FACTOR * lastSpeed + (1-SMOOTHING_FACTOR) * averageSpeed
     if (count($this->_times) > 2) {
         $lastSpeed = $this->_times[count($this->_times) - 1] - $this->_times[count($this->_times) - 2];
         if ($this->_averageSpeed == -1) {
             $this->_averageSpeed = $lastSpeed;
         }
         $this->_averageSpeed = ProgressBar::SMOOTHING_FACTOR * $lastSpeed + (1 - ProgressBar::SMOOTHING_FACTOR) * $this->_averageSpeed;
         $output .= ' ETA ' . $this->_mtime2str(round($this->_averageSpeed * ($this->_max - $progress)));
         $output .= ' ' . date('H:i:s', time() + round($this->_averageSpeed * ($this->_max - $progress)));
     }
     echo "\r" . $output . '  ';
 }
コード例 #11
0
ファイル: DaofuAction.class.php プロジェクト: kevicki/pig
	public function pay()
	{
		$orderName = $_GET['orderName'];

		if (!$orderName) {
			$orderName = microtime();
		}

		$orderid = $_GET['orderid'];

		if (!$orderid) {
			$orderid = $_GET['single_orderid'];
		}

		$payHandel = new payHandle($this->token, $_GET['from'], 'daofu');
		$orderInfo = $payHandel->beforePay($orderid);

		if (!$orderInfo['price']) {
			exit('必须有价格才能支付');
		}

		$orderInfo = $payHandel->afterPay($orderid, '');
		$from = $payHandel->getFrom();
		$this->redirect('/index.php?g=Wap&m=' . $from . '&a=payReturn&token=' . $orderInfo['token'] . '&wecha_id=' . $orderInfo['wecha_id'] . '&nohandle=1&orderid=' . $orderid);
	}
コード例 #12
0
ファイル: Transformer.php プロジェクト: PhantomWatson/macc
 /**
  * Creates a set of files from the initial data and returns them as key/value
  * pairs, where the path on disk maps to name which each file should have.
  * Example:
  *
  *   [
  *     '/tmp/path/to/file/on/disk' => 'file.pdf',
  *     '/tmp/path/to/file/on/disk-2' => 'file-preview.png',
  *   ]
  *
  * @return array key/value pairs of temp files mapping to their names
  */
 public function transform()
 {
     // Get uploaded image from tmp directory
     $imagine = new \Imagine\Gd\Imagine();
     $image = $imagine->open($this->data['tmp_name']);
     // Get path to tmp directory
     $tmpPathParts = explode(DS, $this->data['tmp_name']);
     array_pop($tmpPathParts);
     // remove filename from path
     $tmpPath = implode(DS, $tmpPathParts);
     // Process fullsize image
     if ($this->isTooBig($image)) {
         // Shrink image to max dimensions and save in tmp dir
         $size = new \Imagine\Image\Box(2000, 2000);
         $mode = \Imagine\Image\ImageInterface::THUMBNAIL_INSET;
         $tmpFullsize = microtime() . $this->data['name'];
         $image->thumbnail($size, $mode)->save($tmpPath . DS . $tmpFullsize);
         $retval[$tmpPath . DS . $tmpFullsize] = $this->data['name'];
     } else {
         $retval[$this->data['tmp_name']] = $this->data['name'];
     }
     // Create thumbnail
     $size = new \Imagine\Image\Box(200, 200);
     $mode = \Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND;
     $thumbFilename = $this->generateThumbnailFilename($this->data['name']);
     $image->thumbnail($size, $mode)->save($tmpPath . DS . $thumbFilename);
     $retval[$tmpPath . DS . $thumbFilename] = $thumbFilename;
     return $retval;
 }
コード例 #13
0
ファイル: Microtime.php プロジェクト: hunde/bsc
 /**
  * Compute a version out of microtime(true)
  *
  * @return string $version
  */
 protected function _microtime()
 {
     $version = microtime(true) - 1073741824;
     // 31 bits
     $version = str_replace('.', '', (string) $version);
     return substr($version, 0, $this->accuracy);
 }
コード例 #14
0
 /**
  * Causes the sleep until a condition is satisfied by the function $lambda when it returns a true value.
  *
  * @param Callable $lambda function to run
  * @param int $wait time to wait for timeout, in milliseconds
  * @param int $pause time to pause between iterations, in milliseconds
  *
  * @return bool
  * @throws \Exception (when timeout occurs)
  */
 public function spin($lambda, $wait = 5000, $pause = 250)
 {
     $e = null;
     $time_start = microtime(true);
     $time_end = $time_start + $wait / 1000.0;
     while (microtime(true) < $time_end) {
         $e = null;
         try {
             if ($lambda($this)) {
                 return true;
             }
         } catch (\Exception $e) {
             // do nothing
         }
         usleep($pause);
     }
     $backtrace = debug_backtrace();
     if (!array_key_exists('file', $backtrace[1])) {
         $backtrace[1]['file'] = '[unknown_file]';
     }
     if (!array_key_exists('line', $backtrace[1])) {
         $backtrace[1]['line'] = '[unknown_line]';
     }
     $message = "Timeout thrown by " . $backtrace[1]['class'] . "::" . $backtrace[1]['function'] . "()\n" . $backtrace[1]['file'] . ", line " . $backtrace[1]['line'];
     throw new \Exception($message, 0, $e);
 }
コード例 #15
0
ファイル: _header.php プロジェクト: IanMage1/WhiteSpace
function checkAuth($redirectIfNeeded)
{
    // is the user already logged in?
    if (isset($_SESSION["uid"]) && $_SESSION["uid"] != "") {
        // yes, already logged in
        return $_SESSION["uid"];
    } else {
        if ($redirectIfNeeded) {
            // user is not logged in and needs to do so
            // send to the login page
            // pass the current URL so that we can come back here after login
            $currentUrl = currentUrl();
            // rawurlencode converts the string so it's safe to pass as a URL GET parameter
            $urlOfLogin = "******" . rawurlencode($currentUrl) . "&cb=" . microtime(true);
            // use a JavaScript redirect; FYI, there's also an http header (Location:) that
            //    can be used to redirect, but that MUST be sent before any HTML, and this
            //    function (checkAuth) might be called after some HTML is sent
            echo "<script>location.replace('{$urlOfLogin}');</script>";
            return "";
        } else {
            // user is not logged in, but whoever called this function doesn't care
            return "";
        }
    }
}
コード例 #16
0
ファイル: display.php プロジェクト: emildev35/processmaker
 /**
  * Constructs a new Log_display object.
  *
  * @param string $name     Ignored.
  * @param string $ident    The identity string.
  * @param array  $conf     The configuration array.
  * @param int    $level    Log messages up to and including this level.
  * @access public
  */
 function Log_display($name = '', $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG)
 {
     if (!class_exists('G')) {
         $realdocuroot = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
         $docuroot = explode('/', $realdocuroot);
         array_pop($docuroot);
         $pathhome = implode('/', $docuroot) . '/';
         array_pop($docuroot);
         $pathTrunk = implode('/', $docuroot) . '/';
         require_once $pathTrunk . 'gulliver/system/class.g.php';
     }
     $this->_id = G::encryptOld(microtime());
     $this->_ident = $ident;
     $this->_mask = Log::UPTO($level);
     if (isset($conf['error_prepend'])) {
         $this->_error_prepend = $conf['error_prepend'];
     } else {
         $this->_error_prepend = ini_get('error_prepend_string');
     }
     if (isset($conf['error_append'])) {
         $this->_error_append = $conf['error_append'];
     } else {
         $this->_error_append = ini_get('error_append_string');
     }
     if (isset($conf['linebreak'])) {
         $this->_linebreak = $conf['linebreak'];
     }
 }
コード例 #17
0
ファイル: emailtopdf.php プロジェクト: swk/bluebox
 public static function processemail($emailsrc, $pdfout, $coverfile = '')
 {
     $combfilelist = array();
     # Process the email
     $emailparts = Mail_mimeDecode::decode(array('include_bodies' => true, 'decode_bodies' => true, 'decode_headers' => true, 'input' => file_get_contents($emailsrc), 'crlf' => "\r\n"));
     # Process the cover if it exists
     if ($coverfile !== '') {
         $combfilelist[] = self::processpart(file_get_contents($coverfile), mime_content_type($coverfile));
     }
     # Process the parts
     $combfilelist = array_merge($combfilelist, self::processparts($emailparts));
     # Create an intermediate file to build the pdf
     $tmppdffilename = sys_get_temp_dir() . '/e2p-' . (string) abs((int) (microtime(true) * 100000)) . '.pdf';
     # Build the command to combine all of the intermediate files into one
     $conbcom = str_replace(array_merge(array('INTFILE', 'COMBLIST'), array_keys(self::$driver_paths)), array_merge(array($tmppdffilename, implode(' ', $combfilelist)), array_values(self::$driver_paths)), self::$mime_drivers['gs']);
     exec($conbcom);
     # Remove the intermediate files
     foreach ($combfilelist as $combfilename) {
         unlink($combfilename);
     }
     # Write the intermediate file to the final destination
     $intfileres = fopen($tmppdffilename, 'rb');
     $outfileres = fopen($pdfout, 'ab');
     while (!feof($intfileres)) {
         fwrite($outfileres, fread($intfileres, 8192));
     }
     fclose($intfileres);
     fclose($outfileres);
     # Remove the intermediate file
     unlink($tmppdffilename);
 }
コード例 #18
0
ファイル: File.php プロジェクト: khsk/ethnam
 /**
  *  ログを出力する
  *
  *  @access public
  *  @param  int     $level      ログレベル(LOG_DEBUG, LOG_NOTICE...)
  *  @param  string  $message    ログメッセージ(+引数)
  */
 function log($level, $message)
 {
     if ($this->fp == null) {
         return;
     }
     $microtime = microtime(true);
     $sec = floor($microtime);
     $msec = floor(($microtime - $sec) * 1000);
     $prefix = sprintf('%s.%03d %s ', strftime('%Y/%m/%dT%H:%M:%S', $sec), $msec, $this->ident);
     if (array_key_exists("pid", $this->option)) {
         $prefix .= sprintf('[%d]', getmypid());
     }
     $prefix .= sprintf('(mem:%s)', number_format(memory_get_usage()));
     $prefix .= sprintf('(%s): ', $this->_getLogLevelName($level));
     if (array_key_exists("function", $this->option) || array_key_exists("pos", $this->option)) {
         $tmp = "";
         $bt = $this->_getBacktrace();
         if ($bt && array_key_exists("function", $this->option) && $bt['function']) {
             $tmp .= $bt['function'];
         }
         if ($bt && array_key_exists("pos", $this->option) && $bt['pos']) {
             $tmp .= $tmp ? sprintf('(%s)', $bt['pos']) : $bt['pos'];
         }
         if ($tmp) {
             $prefix .= $tmp . ": ";
         }
     }
     fwrite($this->fp, $prefix . $message . "\n");
     return $prefix . $message;
 }
コード例 #19
0
ファイル: Data.php プロジェクト: hillstill/sooh
 protected function newLogId($plan = 'c')
 {
     $dt = microtime(true);
     list($s, $ms) = explode('.', $dt);
     $s = $s - 1435680000;
     //18446744073709551616
     //17------------------  18组服务器
     //--1234567890--------  时间戳
     //------------sss-----  毫秒
     //---------------12345  进程
     switch ($plan) {
         case 'a':
             //plan-a 180组服务器,30几年后溢出,(每个请求需要一个进程处理至少1个毫秒,)
             $this->plan = 'a';
             return sprintf("%03d%09d%03d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 3), getmypid());
         case 'b':
             //plan-b 18组服务器, 300年后溢出, (每个请求需要一个进程处理至少1个毫秒,)
             $this->plan = 'b';
             return sprintf("%02d%010d%03d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 3), getmypid());
         case 'c':
             //plan-c 18组服务器, 30年后溢出,  (每个请求需要一个进程处理至少0.1个毫秒,)
             $this->plan = 'c';
             return sprintf("%02d%09d%04d%05d", \Sooh\Base\Ini::getInstance()->get('ServerId', 0), $s, substr($ms, 0, 4), getmypid());
         default:
             throw new \Sooh\Base\ErrException('unknown support log-guid-generate');
     }
 }
コード例 #20
0
ファイル: Benchmark.php プロジェクト: Dirichi/Ushahidi_Web
 /**
  * Set a benchmark stop point.
  *
  * @param   string  benchmark name
  * @return  void
  */
 public static function stop($name)
 {
     if (isset(self::$marks[$name]) and self::$marks[$name]['stop'] === FALSE) {
         self::$marks[$name]['stop'] = microtime(TRUE);
         self::$marks[$name]['memory_stop'] = function_exists('memory_get_usage') ? memory_get_usage() : 0;
     }
 }
コード例 #21
0
ファイル: debug.php プロジェクト: joyerma/yongzhuo
 public function stop()
 {
     $time = round(microtime(true) - $this->time_point, 5);
     $memory = round(memory_get_usage() - $this->memory_point, 5);
     $memory = $this->memory_format($memory);
     return array('time' => $time, 'memory' => $memory);
 }
コード例 #22
0
 /**
  * @param  \Kbrw\RiakBundle\Model\Cluster\Cluster $cluster
  * @param  \Kbrw\RiakBundle\Model\Bucket\Bucket   $bucket
  * @param  \Kbrw\RiakBundle\Model\MapReduce\Query $query
  * @return mixed
  */
 public function mapReduce($cluster, $query)
 {
     try {
         $request = $this->getClient($cluster->getGuzzleClientProviderService(), $this->getConfig($cluster))->post();
         $extra = array("method" => "POST");
         $ts = microtime(true);
         $body = $this->getSerializer()->serialize($query, "json");
         $extra["serialization_time"] = microtime(true) - $ts;
         $request->setBody($body, "application/json");
         $response = $request->send();
         if ($response->getStatusCode() === 200) {
             $fqcn = $query->getResponseFullyQualifiedClassName();
             if (!empty($fqcn)) {
                 $ts = microtime(true);
                 $content = $this->getSerializer()->deserialize($response->getBody(true), $fqcn, "json");
                 $extra["serialization_time"] = microtime(true) - $ts;
                 $this->logResponse($response, $extra);
                 return $content;
             }
             $this->logResponse($response, $extra);
             return $response->getBody(true);
         }
         $this->logResponse($response, $extra);
     } catch (CurlException $e) {
         $this->logger->err("Riak is unavailable" . $e->getMessage());
         throw new RiakUnavailableException();
     } catch (\Exception $e) {
         $this->logger->err("Unable to execute a mapreduce query. Full message is : \n" . $e->getMessage() . "");
     }
     return null;
 }
コード例 #23
0
function regenerateSession($reload = false)
{
    // This token is used by forms to prevent cross site forgery attempts
    if (!isset($_SESSION['nonce']) || $reload) {
        $_SESSION['nonce'] = md5(microtime(true));
    }
    if (!isset($_SESSION['IPaddress']) || $reload) {
        $_SESSION['IPaddress'] = $_SERVER['REMOTE_ADDR'];
    }
    if (!isset($_SESSION['userAgent']) || $reload) {
        $_SESSION['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
    }
    //$_SESSION['user_id'] = $this->user->getId();
    // Set current session to expire in 1 minute
    $_SESSION['OBSOLETE'] = true;
    $_SESSION['EXPIRES'] = time() + 60;
    // Create new session without destroying the old one
    session_regenerate_id(false);
    // Grab current session ID and close both sessions to allow other scripts to use them
    $newSession = session_id();
    session_write_close();
    // Set session ID to the new one, and start it back up again
    session_id($newSession);
    session_start();
    // Don't want this one to expire
    unset($_SESSION['OBSOLETE']);
    unset($_SESSION['EXPIRES']);
}
コード例 #24
0
 public function testRegularUser()
 {
     $originalUser = $this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface');
     $user = new UserWrapped($originalUser, $this->apiUser);
     $this->assertTrue($user->isEnabled());
     $this->assertTrue($user->isAccountNonExpired());
     $this->assertTrue($user->isAccountNonLocked());
     $this->assertTrue($user->isCredentialsNonExpired());
     $this->assertTrue($user->isEqualTo($this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface')));
     $originalUser->expects($this->once())->method('eraseCredentials');
     $user->eraseCredentials();
     $username = '******';
     $password = '******';
     $roles = array('ROLE_USER', 'ROLE_TEST');
     $salt = md5(microtime(true));
     $originalUser->expects($this->exactly(2))->method('getUsername')->will($this->returnValue($username));
     $originalUser->expects($this->once())->method('getPassword')->will($this->returnValue($password));
     $originalUser->expects($this->once())->method('getRoles')->will($this->returnValue($roles));
     $originalUser->expects($this->once())->method('getSalt')->will($this->returnValue($salt));
     $this->assertSame($username, $user->getUsername());
     $this->assertSame($username, (string) $user);
     $this->assertSame($password, $user->getPassword());
     $this->assertSame($roles, $user->getRoles());
     $this->assertSame($salt, $user->getSalt());
     $this->assertSame($originalUser, $user->getWrappedUser());
 }
コード例 #25
0
 /**
  * get new connection
  * @param string $group
  * @param string $node
  * @param string $role
  * @return boolean|resource
  */
 protected function getNewConnection($group, $node, $role)
 {
     $servers = $this->configHandle->get("cache.servers");
     $hostTotal = count($servers[$group][$node][$role]);
     $hostIndexArray = array_keys($servers[$group][$node][$role]);
     while ($hostTotal) {
         $hashNumber = substr(microtime(), 7, 1) % $hostTotal;
         $hostConfig = $servers[$group][$node][$role][$hostIndexArray[$hashNumber]];
         $cacheFactory = new LtCacheAdapterFactory();
         $this->connectionAdapter = $cacheFactory->getConnectionAdapter($hostConfig["adapter"]);
         if ($connection = $this->connectionAdapter->connect($hostConfig)) {
             return $connection;
         } else {
             //trigger_error('connection fail', E_USER_WARNING);
             //delete the unavailable server
             for ($i = $hashNumber; $i < $hostTotal - 1; $i++) {
                 $hostIndexArray[$i] = $hostIndexArray[$i + 1];
             }
             unset($hostIndexArray[$hostTotal - 1]);
             $hostTotal--;
         }
         //end else
     }
     //end while
     return false;
 }
コード例 #26
0
function wsl_watchdog_log_to_database($action_name, $action_args = array(), $user_id = 0, $provider = '')
{
    global $wpdb;
    $sql = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}wslwatchdog` ( \n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `session_id` varchar(50) NOT NULL,\n\t\t\t  `user_id` int(11) NOT NULL,\n\t\t\t  `user_ip` varchar(50) NOT NULL,\n\t\t\t  `url` varchar(450) NOT NULL,\n\t\t\t  `provider` varchar(50) NOT NULL,\n\t\t\t  `action_name` varchar(255) NOT NULL,\n\t\t\t  `action_args` text NOT NULL,\n\t\t\t  `is_connected` int(11) NOT NULL,\n\t\t\t  `created_at` varchar(50) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`) \n\t\t\t)";
    $wpdb->query($sql);
    $wpdb->insert("{$wpdb->prefix}wslwatchdog", array("session_id" => session_id(), "user_id" => $user_id, "user_ip" => $_SERVER['REMOTE_ADDR'], "url" => wsl_get_current_url(), "provider" => $provider, "action_name" => $action_name, "action_args" => json_encode($action_args), "is_connected" => get_current_user_id() ? 1 : 0, "created_at" => microtime(true)));
}
コード例 #27
0
ファイル: TaskRunner.php プロジェクト: php-task/php-task
 /**
  * {@inheritdoc}
  */
 public function runTasks()
 {
     $executions = $this->taskExecutionRepository->findScheduled();
     foreach ($executions as $execution) {
         $handler = $this->taskHandlerFactory->create($execution->getHandlerClass());
         $start = microtime(true);
         $execution->setStartTime(new \DateTime());
         $execution->setStatus(TaskStatus::RUNNING);
         $this->taskExecutionRepository->save($execution);
         try {
             $this->eventDispatcher->dispatch(Events::TASK_BEFORE, new TaskExecutionEvent($execution->getTask(), $execution));
             $result = $handler->handle($execution->getWorkload());
             $execution->setStatus(TaskStatus::COMPLETED);
             $execution->setResult($result);
             $this->eventDispatcher->dispatch(Events::TASK_PASSED, new TaskExecutionEvent($execution->getTask(), $execution));
         } catch (\Exception $ex) {
             $execution->setException($ex->__toString());
             $execution->setStatus(TaskStatus::FAILED);
             $this->eventDispatcher->dispatch(Events::TASK_FAILED, new TaskExecutionEvent($execution->getTask(), $execution));
         }
         $execution->setEndTime(new \DateTime());
         $execution->setDuration(microtime(true) - $start);
         $this->eventDispatcher->dispatch(Events::TASK_FINISHED, new TaskExecutionEvent($execution->getTask(), $execution));
         $this->taskExecutionRepository->save($execution);
     }
 }
コード例 #28
0
ファイル: daemon.php プロジェクト: altesien/FinalProject
 /**
  * Constructs a new syslog object.
  *
  * @param string $name     The syslog facility.
  * @param string $ident    The identity string.
  * @param array  $conf     The configuration array.
  * @param int    $maxLevel Maximum level at which to log.
  * @access public
  */
 function Log_daemon($name, $ident = '', $conf = array(), $level = PEAR_LOG_DEBUG)
 {
     /* Ensure we have a valid integer value for $name. */
     if (empty($name) || !is_int($name)) {
         $name = LOG_SYSLOG;
     }
     $this->_id = md5(microtime());
     $this->_name = $name;
     $this->_ident = $ident;
     $this->_mask = Log::UPTO($level);
     if (isset($conf['ip'])) {
         $this->_ip = $conf['ip'];
     }
     if (isset($conf['proto'])) {
         $this->_proto = $conf['proto'];
     }
     if (isset($conf['port'])) {
         $this->_port = $conf['port'];
     }
     if (isset($conf['maxsize'])) {
         $this->_maxsize = $conf['maxsize'];
     }
     if (isset($conf['timeout'])) {
         $this->_timeout = $conf['timeout'];
     }
     $this->_proto = $this->_proto . '://';
     register_shutdown_function(array(&$this, '_Log_daemon'));
 }
コード例 #29
0
 private function invokeStats(array $options, RequestInterface $request, $startTime, ResponseInterface $response = null, $error = null)
 {
     if (isset($options['on_stats'])) {
         $stats = new TransferStats($request, $response, microtime(true) - $startTime, $error, []);
         call_user_func($options['on_stats'], $stats);
     }
 }
コード例 #30
-1
ファイル: webservice.php プロジェクト: centaurustech/eollice
 function getToken($table, $campo, $uc = TRUE, $n = TRUE, $sc = TRUE, $largo = 15)
 {
     $db = new db_core();
     $source = 'abcdefghijklmnopqrstuvwxyz';
     if ($uc == 1) {
         $source .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
     }
     if ($n == 1) {
         $source .= '1234567890';
     }
     if ($sc == 1) {
         $source .= '|@#~$%()=^*+[]{}-_';
     }
     $rstr = "";
     while (true) {
         $rstr = "";
         $source = str_split($source, 1);
         for ($i = 1; $i <= $largo; $i++) {
             mt_srand((double) microtime() * 1000000);
             $num = mt_rand(1, count($source));
             $rstr .= $source[$num - 1];
         }
         if (!$db->isExists($table, $campo, $rstr)) {
             break;
         }
     }
     return $rstr;
 }