PHPDaemon\Core\Debug::backtrace PHP Method

backtrace() public static method

Returns textual backtrace
public static backtrace ( $bool = false ) : string
return string
    public static function backtrace($bool = false)
    {
        if (Daemon::$obInStack || $bool) {
            try {
                throw new \Exception();
            } catch (\Exception $e) {
                $trace = $e->getTraceAsString();
                $e = explode("\n", $trace);
                array_shift($e);
                array_shift($e);
                return implode("\n", $e);
            }
        }
        ob_start();
        debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        $trace = ob_get_contents();
        ob_end_clean();
        $e = explode("\n", $trace);
        array_shift($e);
        return implode("\n", $e);
    }

Usage Example

Esempio n. 1
0
 /**
  * Returns string of pseudo random characters
  * @param  integer  $len   Length of desired string
  * @param  string   $chars String of allowed characters
  * @param  callable $cb    Callback
  * @param  integer  $pri   Priority of EIO operation
  * @param  boolean  $hang  If true, we shall use /dev/random instead of /dev/urandom and it may cause a delay
  * @return string
  */
 public static function randomString($len = null, $chars = null, $cb = null, $pri = 0, $hang = false)
 {
     if ($len === null) {
         $len = 64;
     }
     if ($chars === null) {
         $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-.';
     }
     if ($cb === null) {
         Daemon::log('[CODE WARN] \\PHPDaemon\\Utils\\Crypt::randomString: non-callback way is not secure.' . ' Please rewrite your code with callback function in third argument' . PHP_EOL . Debug::backtrace());
         $r = '';
         $m = strlen($chars) - 1;
         for ($i = 0; $i < $len; ++$i) {
             $r .= $chars[mt_rand(0, $m)];
         }
         return $r;
     }
     $charsLen = strlen($chars);
     $mask = static::getMinimalBitMask($charsLen - 1);
     $iterLimit = max($len, $len * 64);
     static::randomInts(2 * $len, function ($ints) use($cb, $chars, $charsLen, $len, $mask, &$iterLimit) {
         if ($ints === false) {
             call_user_func($cb, false);
             return;
         }
         $r = '';
         for ($i = 0, $s = sizeof($ints); $i < $s; ++$i) {
             // This is wasteful, but RNGs are fast and doing otherwise adds complexity and bias
             $c = $ints[$i] & $mask;
             // Only use the random number if it is in range, otherwise try another (next iteration)
             if ($c < $charsLen) {
                 $r .= static::stringIdx($chars, $c);
             }
             // Guarantee termination
             if (--$iterLimit <= 0) {
                 return false;
             }
         }
         $d = $len - strlen($r);
         if ($d > 0) {
             static::randomString($d, $chars, function ($r2) use($r, $cb) {
                 call_user_func($cb, $r . $r2);
             });
             return;
         }
         call_user_func($cb, $r);
     }, $pri, $hang);
 }
All Usage Examples Of PHPDaemon\Core\Debug::backtrace