Here's my modified version with a few more sanity checks, it even waits for your balance to be confirmed.
I was testing it out and it worked great, but one issue was, I had it running so quickly, that I ran out of confirmed balance, and had nearly 2BTC unconfirmed, so I added a function to check whether you actually have enough balance confirmed to even send it, if not, it waits 1 minute, and repeats until you have enough balance.
require_once('jsonRPCClient.php');
/** BITCOIN **/
$btcu = array("user" => "", // RPC Username
"pass" => "", // RPC Password
"host" => "localhost", // RPC Hostname/IP
"port" => 9332); // RPC Port
$b = new jsonRPCClient("http://{$btcu['user']}:{$btcu['pass']}@{$btcu['host']}:{$btcu['port']}");
define('MIN_BET', 0.05);
define('MAX_BET', 6);
define('ADDRESS', '1dice97ECuByXAvqXpaYzSaQuPVvrtmz6');
$bet = MIN_BET;
$total_fees = 0;
$count = 0;
$count_won = 0;
while (($bet <= MAX_BET) && ($count_won < 200))
{
$balance_a = $b->getbalance('*', 0);
if (!isset($starting_balance)) $starting_balance = $balance_a;
if($b->getbalance('*', 1) < $bet) { // If we don't have enough confirmed bitcoins to send to satoshi dice...
echo "Waiting for confirmed balance";
while($b->getbalance('*', 1) < $bet)
{
echo ".";
sleep(60); // Wait a full minute before checking the balance again.
}
echo "\n";
}
try // Wrapped in a try catch block just incase we run out of cash.
{
$b->sendtoaddress(ADDRESS, (float) $bet);
}
catch(Exception $e)
{
echo "Have: " . $b->getbalance('*', 1) . " Needed: " . $bet . "\n";
die("Ran out of money?\n");
}
$balance_b = $b->getbalance('*', 0);
$count++;
$fee = $balance_a - $balance_b - $bet;
$total_fees += $fee;
$total_fees = number_format($total_fees,8,'.','')+0;
echo 'Game #'.$count."\n";
echo 'Balance: ' . $balance_a." ";
echo 'Bet: '. $bet." ";
echo 'Fee: '. (number_format($fee, 8, '.', '') +0) . " ";
echo 'Total Fees: '. $total_fees. "\n";
echo 'Balance: ' . $balance_b . " ".'Waiting';
$balance_c = 0;
while ($balance_b >= $balance_c)
{
sleep(4);
$balance_c = $b -> getbalance('*', 0);
echo '.';
}
echo "\nBalance: $balance_c ";
$diff = $balance_c - $balance_b;
if ($diff > $bet)
{
$bet = MIN_BET;
$count_won++;
echo "Win! ($count_won out of $count)\n";
}
else
{
$bet *= 2;
echo 'Lose!'."\n";
}
echo "\n";
}
echo 'Starting Balance: '.$starting_balance."\n";
echo 'Ending Balance : '. $balance_c."\n";
echo 'Total Fees: '. $total_fees."\n";
$amt_won = $balance_c - $starting_balance;
echo 'Net Profit: '. (number_format($amt_won,8,'.','') + 0). "\n\n";
?>