我正在测试PHP5.5的新password_hash
技术,出于调试目的,我希望每次for
循环完成时都有PHP回显,而不是等待页面完成加载(或者用apache来削减它)。我正在使用wamp服务器进行调试,并启用了implicit_flush
,并禁用了output_buffering
。
我的代码是:
<?php
ob_start();
$wordtohash = "rasmuslerdorf";
//require ircmaxell's PHP5 backward compat lib (https://github.com/ircmaxell/password_compat)
require 'lib/pw.php';
echo "Beginning hashing: <br /><br /><hr /><br />";
ob_flush();
$options = [
'cost' => 15
];
for ($i=0; $i < 10; $i++) {
if (isset($hashed)) {
$wordtohash = $hashed;
}
//start counting
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$start = $mtime;
//hash
$hashed = "Attempt {$i}: ".password_hash($wordtohash, PASSWORD_BCRYPT, $options);
//end counting
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$end = $mtime;
$totaltime = ($end - $start);
echo $hashed." (total time: ".$totaltime." seconds)<br /><br />";
ob_flush();
}
?>
这样做是对一个测试词“rasmuslerdorf”进行哈希处理,并收集哈希值,然后将其发送回哈希值(与循环指定的次数相同)。
我为每个人设置了一个计时器,但是当他们完成测试时,他们希望每个都显示在页面上。
我已尝试在需要时使用ob_start()
后跟ob_flush()
命令,但这不起作用(implicit_flush
应该使其在echo
或{{ 1}},所以我很茫然)我也试过print
。
有没有人碰巧有任何额外的想法?非常感谢。
答案 0 :(得分:1)
我会尝试使用PHP的error_log()函数:
$string = $hashed . " (total time: " . $totaltime . " seconds)" ;
error_log(print_r($string, true);
这将实时将调试消息打印到PHP错误日志,而不依赖于应用程序的视图层或中断代码的执行。在UNIX / Linux系统或OS X上,您可以拖尾日志。如果您安装了Cygwin或其他BASH仿真器,也可以在Windows中执行此操作:
tail -f /path/to/your/error.log
您可以使用phpinfo()来确定PHP错误日志的位置。如果您没有在php.ini中为日志指定自定义设置,则PHP可能默认将错误输出到Apache日志。