I wonder if this snippet could help:
#!/usr/bin/env php
/* depends on: */
/* php5-curl */
/* https://github.com/aceat64/EasyBitcoin-PHP */
require_once 'include/easybitcoin.php';
$min_confirm = 6;
$bitcoinrpc_user = 'bitcoinrpc';
$bitcoinrpc_pass = 'bitcoinrpc_pass';
$bitcoinrpc_host = 'localhost';
$bitcoinrpc_port = '8332';
if ($argc != 2 || strlen($argv[1]) != 64)
{
echo "usage:$argv[0] tx\n";
die();
}
$tx = $argv[1];
$file = "/tmp/".md5($tx);
$lock = fopen($file, "w+");
if (flock($lock, LOCK_EX | LOCK_NB))
{
fwrite($lock, $tx);
}
else
{
echo "Process already running for same tx, exiting\n";
die();
}
$bitcoin = new Bitcoin($bitcoinrpc_user, $bitcoinrpc_pass, $bitcoinrpc_host, $bitcoinrpc_port);
$bitcoin->gettransaction($tx);
if ($bitcoin->status != 200)
{
echo "Error: $bitcoin->error\n";
die();
}
if ($bitcoin->response['result']['details'][0]['category'] === "receive")
{
while (1)
{
$bitcoin->gettransaction($tx);
$address =$bitcoin->response['result']['details'][0]['address'];
$amount =$bitcoin->response['result']['amount'];
$confirm =$bitcoin->response['result']['confirmations'];
echo "$address -> $amount confirmations:$confirm\n";
if ($confirm >= $min_confirm)
{
echo "$min_confirm or more confirmations for $tx\n";
$payment = array("address" => $address, "tx" => $tx, "amount" => $amount);
/****************************************** Process tx stored in $payment here ******************************************/
die();
}
sleep(30); // Check number of confirmations every 30sec.
}
}
?>
The infinite loop has to be modified so it won't loop to infinity when getting a tx from a yet to be orphaned block.
Then you only need to add this line to bitcoin.conf to trigger the script for each new tx that is affecting the wallet:
walletnotify=/path_to/script.php %s