Connectors Update [PHP Graphene Node Client v4.0.3]

in #utopian-io7 years ago (edited)

php-graphene-node-client

It is PHP API client for Steem/GOLOS blockchain

Github or packagist with MIT license. Author @t3ran13 and active contributor @semasping

In Release v4.0.3

  • rename HTTP connectors;
  • HTTP connectors use only curl, composer package 'fguillot/json-rpc' was removed;
  • in HttpJsonRpcConnectorAbstract/WSConnectorAbstract some properties was made static and to constructor added ordering node by timeout answer;
  • close old connection before new for WSConnectorAbstract;
  • to SteemitHttpJsonRpcConnector were added new nodes (6 total);
  • new connector for GOLOS GolosHttpJsonRpcConnector;

The main idea of this contribution is testing and ordering nodes in connector by timeout. All down or slow nodes will be skip and faster nodes will be in top. It is enough to test only 1 time during each php process. Each command will be know state of connector after privious. It is awesome for cron scripts with many call to api.

rename HTTP connectors

If you use HTTP connectors from php-graphene-node-client you have to update HTTP connectors nemes as below

//was 
use GrapheneNodeClient\Connectors\Http\SteemitHttpConnector;

$connector = new SteemitHttpConnector(500);

//now 
use GrapheneNodeClient\Connectors\Http\SteemitHttpJsonRpcConnector;

$connector = new SteemitHttpJsonRpcConnector(500);

//if you extend abstract connector
//was 
use GrapheneNodeClient\Connectors\Http\HttpConnectorAbstract;

class SteemitHttpConnector extends HttpConnectorAbstract
{
   ...
}

//now
use GrapheneNodeClient\Connectors\Http\HttpJsonRpcConnectorAbstract;

class SteemitHttpJsonRpcConnector extends HttpJsonRpcConnectorAbstract
{
   ...
}

HTTP connectors use only curl, composer package 'fguillot/json-rpc' was removed

'fguillot/json-rpc' was removed from composer.json and HTTP connector use native CURL.

in HttpJsonRpcConnectorAbstract/WSConnectorAbstract some properties was made static and to constructor added ordering node by timeout answer

Cool feature for scripts where you call to nodes many times, for example in cron script.
When you init connector you can set answer timeout in sec for WS and ms for HTTP, if nodes do not pass it it will be removed from nodes list $nodeURL and passed nodes will be ordered by timeout.

how to use

//WS
use GrapheneNodeClient\Connectors\WebSocket\SteemitWSConnector;

$connector = new SteemitWSConnector(1); //1 sec only during test of timeouts

//HTTP
use GrapheneNodeClient\Connectors\Http\SteemitHttpJsonRpcConnector;

$connector = new SteemitHttpJsonRpcConnector(500); //500 ms only during test of timeouts

If you extend HttpJsonRpcConnectorAbstract/WSConnectorAbstract you have to modify property $nodeURL to static as below

//was
class * extends HttpJsonRpcConnectorAbstract
{
    /**
     * https or http server
     *
     * if you set several nodes urls, if with first node will be trouble
     * it will connect after $maxNumberOfTriesToCallApi tries to next node
     *
     * @var string
     */
    protected $nodeURL = ['https://steemd.privex.io', 'https://rpc.steemviz.com', 'https://api.steemit.com', 'https://rpc.buildteam.io', 'https://steemd.pevo.science', 'https://steemd.minnowsupportproject.org'];
}

//now
class * extends HttpJsonRpcConnectorAbstract
{
    /**
     * https or http server
     *
     * if you set several nodes urls, if with first node will be trouble
     * it will connect after $maxNumberOfTriesToCallApi tries to next node
     *
     * @var string
     */
    protected static $nodeURL = ['https://steemd.privex.io', 'https://rpc.steemviz.com', 'https://api.steemit.com', 'https://rpc.buildteam.io', 'https://steemd.pevo.science', 'https://steemd.minnowsupportproject.org'];
}

close old connection before new for WSConnectorAbstract

When you connected to reserve node old connection do not closed, it was fixed

to SteemitHttpJsonRpcConnector were added new nodes (6 total)

default nodes:

new connector for GOLOS GolosHttpJsonRpcConnector

There is no public HTTP api nodes for GOLOS, you need own node and set up HTTP


It is better with each commit

Commits were done by me for release v4.0.3

  • upd WSConnectorAbstract
  • upd WSConnectorAbstract
  • upd HttpJsonRpcConnectorAbstract without reverse compatibility
  • remove fguillot/json-rpc composer package
  • add GolosHttpJsonRpcConnector
  • upd SteemitHttpJsonRpcConnector and InitConnector
  • upd HttpJsonRpcConnectorAbstract
Sort:  

Its means just using curl and add variable $connector and all ?

It is not
The main idea of this contribution is testing and ordering nodes in connector by timeout. All down or slow nodes will be skip and faster nodes will be in top. It is enough to test only 1 time during each php process. Each command will be know state of connector after privious. It is awesome for cron scripts with many call to api.

Hey @t3ran13
Thanks for contributing on Utopian.
We're already looking forward to your next contribution!

Contributing on Utopian
Learn how to contribute on our website or by watching this tutorial on Youtube.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

thank you!

Hi i have question this is my repository i want help and earn money how can i do this this is my github https://github.com/michal13171

My stack basic node js php symfony and laravel, advance angular 4 javascript html, css

Thank you for your contribution. It would be nice if you would have described why have you done this change and what benefit of its would have been for the user using this library.


Need help? Write a ticket on https://support.utopian.io.

Chat with us on Discord.
[utopian-moderator]

Coin Marketplace

STEEM 0.19
TRX 0.19
JST 0.033
BTC 89479.36
ETH 3038.26
USDT 1.00
SBD 2.80