我正在测试PHP5.5的新password_hash技术,为了调试的目的,我希望每次完成for循环时都有PHP5.5,而不是等待页面完成加载(或者等待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或print上运行,所以我很困惑),我也尝试了flush()。
有没有人碰巧有什么额外的想法?非常感谢。
发布于 2013-10-20 22:32:09
我将尝试使用PHP error_log()函数:
$string = $hashed . " (total time: " . $totaltime . " seconds)" ;
error_log(print_r($string, true);这将实时地将调试消息打印到PHP错误日志,而不依赖应用程序的视图层或中断代码的执行。在UNIX / Linux系统或OS上,您可以跟踪日志。如果安装了Cygwin或其他BASH模拟器,也可以在windows中这样做:
tail -f /path/to/your/error.log 您可以使用phpinfo()来确定PHP错误日志的位置。如果您没有在Apache中为日志指定自定义设置,php.ini很可能默认情况下会将错误输出到Apache日志。
https://stackoverflow.com/questions/19483579
复制相似问题