See above. Basically, argc is the number of arguments on the command line, including the name of the script. argv is an array of the command line elements, starting with argv[0] set to the name of the script.
I got it to work with argc and argv. I put the following into bitcoin.conf:
walletnotify=/usr/bin/php /path/to/walletnotify.php %s
I have the following in walletnotify.php:
if(2==$argc){
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://username:[email protected]:8332/');
$walletinfo = $bitcoin->getinfo();
$trxinfo = $bitcoin->gettransaction($argv[1]);
// Append data to the file
$new = "\n\nTransaction hash: ".$argv[1]."\nGetinfo balance: ".$walletinfo["balance"]
."\n Gettransaction amount: ".$trxinfo["amount"]
."\n Gettransaction confirmations: ".$trxinfo["confirmations"]
."\n Gettransaction blockhash: ".$trxinfo["blockhash"]
."\n Gettransaction blockindex: ".$trxinfo["blockindex"]
."\n Gettransaction blocktime: ".$trxinfo["blocktime"]
."\n Gettransaction txid: ".$trxinfo["txid"]
."\n Gettransaction time: ".$trxinfo["time"]
."\n Gettransaction timereceived: ".$trxinfo["timereceived"]
."\n Gettransaction account: ".$trxinfo["details"][0]["account"]
."\n Gettransaction address: ".$trxinfo["details"][0]["address"]
."\n Gettransaction category: ".$trxinfo["details"][0]["category"]
."\n Gettransaction amount: ".$trxinfo["details"][0]["amount"]
//."\n Gettransaction fee: ".$trxinfo["details"][0]["fee"] // According to https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list, fee is returned, but it doesn't seem that way here
;
$fp=fopen("/tmp/notify_wallet.txt","a");
fwrite($fp,$new);
}
?>
When I send testnet coins from my eWallet to my Bitcoin-QT, the above walletnotify.php fetches the transaction's data from the wallet and writes it to the text file. It works well.
I didn't need the following code:
!/bin/php
Thanks for your help!