I'm testing PHP5.5's new password_hash
technique and, for debug purposes, am wanting to have PHP echo each time my for
loop finishes, instead of waiting for the page to finish loading (or for apache to cut it). I am using wamp server for my debugging, and have enabled implicit_flush
, and disabled output_buffering
.
My code is:
<?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();
}
?>
What this is doing is hashing a test word, "rasmuslerdorf", and collecting the hash and then sending that back in to be hashed (for as many times as the loop specifies).
I have a timer set up for each, but would like to have each show up on the page as they finish for testing.
I have tried using ob_start()
followed by ob_flush()
commands where needed, but that didn't work (implicit_flush
is supposed to make it flush on echo
or print
, so I'm at a loss) and I have also tried flush()
.
Does anyone happen to have any extra ideas? Much appreciated.