I'm not talking about CPU cycles, I'm concerned about network traffic. Not everyone is going to have their RPC server hosted on the same machine as their site. I'm willing to best most actually go the 3rd-party route, and outsource their RPC server.
I'm assuming your saying that doing a global connection object would be less networking and more efficient but it wouldn't be for a few reasons:
Unless I force developers to "prerender" their data (like obstart and obflush) for example "call" all Bitcoin queries in one swoop instead of "as needed on the page" basis, the reasoning is JSONRPC libraries for php are not "socket" based, only http so even forcing them to prerender at this point is just making things difficult and confusing for the gain of nothing.
If i had socket based json php library this could work and with out forcing pre render scenario too, so I'll say it again I agree with you it just needs to be done right, I can't just set the connection object to global and expect HTTP requests spanned out in different areas of a logical PHP to execute in a continuous stream like TCP and expect to get greater networking efficency... nope not with out TCP sockets or a consistent stream.
Also if a user is executing more than 5 bitcoin commands in 1 second you probably should hire a developer to develop a larger scale system or don't use BDKphp for cronjob type tasks use python or C++ or some other choice of language built for that sort of thing.
As for "creating an object", the jsonRPC library already returns the connection as a class object. All you need to do is have it set as public at the top of the script (after including jsonRPCClient.php and config.php, of course).
See the following... //Open connection
try{
$output["connection"] = new jsonRPCClient($btcclient["https"].'://'.$btcclient["user"].':'.$btcclient["pass"].'@'.$btcclient["host"].':'.$btcclient["port"]);
}catch(Exception $e){
$output["return_status"] = -1;
$output["connection"] = null;
}
if($output["connection"] != null && $output["connection"] != false){
//Keep running multiple bitcoin commands
for($i=0;$i<100;$i++){
//Connection successful run query to Bitcoin
//Yes BTC client has been successfully opened
//Attempt to query a new address....
$tmp_new_address = '';
try{
$tmp_new_address = $new_btcclient_connection["connection"]->getnewaddress($new_address_label);
}catch(Exception $e){
$tmp_new_address = '';
}
$generated_address_is_valid = bitcoin_validate_address($tmp_new_address);
if($generated_address_is_valid["isvalid"] == 1){
echo "new address".$tmp_new_address;
}else{
echo "FAILED";
}
}
}
In comparison to just doing the following...include_once("./BDKp_library.php");
$new_address_details = bitcoin_generate_new_address();
Now if your saying that setting the connection script to global and doing JSON commands one right after another instantaneously will save networking resources then you should look into the JSON libraries for PHP more closely on how each call is made I guarantee you none of them have a queuing system that say "Hey is ther another command coming so I can finally send this HTTP request?" that would bottle neck things.