nbobtc/bitcoind-php
Composer 安装命令:
composer require nbobtc/bitcoind-php
包简介
PHP Wrapper for a bitcoind daemon
README 文档
README
This project is used to interact with a headless bitcoin program called bitcoind. It also contains various utility classes for working with Bitcoin as a PHP Developer.
Installation
You can install this library by using Composer. You can also view more info about this on Packagist.
composer require nbobtc/bitcoind-php
Usage
To use the project you need to just create a new instance of the class.
<?php require __DIR__ . '/vendor/autoload.php'; $command = new \Nbobtc\Command\Command('getinfo'); $client = new \Nbobtc\Http\Client('https://username:password@localhost:18332'); /** @var \Nbobtc\Http\Message\Response */ $response = $client->sendCommand($command); /** @var string */ $contents = $response->getBody()->getContents(); echo $contents;
You are able to get the Request and Response objects back from
the client with the correct getters: getRequest() and getResponse().
You can also parse the response however you wish to do so since the result is returned to you as a string. See below for some ideas!
Commands
Commands are created in such a way that this will support any future updates the Bitcoin API by providing you with an easy class that sets all the required information.
You are able to pass into the object the method and the parameters that are
required. Here are a few examples:
// No Parameters $command = new Command('getinfo'); // One Parameter $command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'); // Multiple Parameters $command = new Command('sendfrom', array('fromaccount', 'tobitcoinaddress', 'amount'));
The second argument MUST be in the same order as on the Bitcoin API wiki page. There is no need to assign the values any keys.
Parameters
Parameters are the second argument when creating a new Command. This argument can either be a string OR an array. For example, both of these are valid.
$command = new Command('getblock', array('000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f')); $command = new Command('getblock', '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f');
Most commands in the Bitcoin API take one parameter. If it takes MORE than one, you must pass the parameters in as an array in the ORDER you find them on that page.
Extending Commands
If, for any reason, you need to extend a command, it MUST implement CommandInterface. You can find documentation within the interface on how to implement this.
Drivers
Drivers are used by the ClientInterface for connecting to a bitcoind service and sending Requests. The return a Response. If you need to implement a new driver take a look at the DriverInterface.
cURL Driver
This is used by default and allows you a lot of options for customizing it to your needs.
You can set various cURL Options by passing them into the function
addCurlOption($option, $value).
Here's an example of how to configure and use the driver.
$driver = new \Nbobtc\Http\Driver\CurlDriver(); $driver ->addCurlOption(CURLOPT_VERBOSE, true) ->addCurlOption(CURLOPT_STDERR, '/var/logs/curl.err'); $client = new \Nbobtc\Http\Client('https://username:password@localhost:18332'); $client->withDriver($driver);
Feel free to take a look at the CurlDriver source code.
Cookbook
How to enable a Keep-Alive ie Persistent Connection
This example shows how you are able to set the client up to Persistent Connection.
$client = new \Nbobtc\Http\Client('https://username:password@localhost:18332'); $client->getRequest()->withHeader('Connection', 'Keep-Alive');
How to set a CA Cert
This library provides some wonderful flexibility that will allow you to configure the client to use your own CA Cert.
$driver = new \Nbobtc\Http\Driver\CurlDriver(); $driver->addCurlOption(CURLOPT_CAINFO, '/path/to/cert'); $client = new \Nbobtc\Http\Client('https://username:password@localhost:18332'); $client->withDriver($driver);
How to Convert Output to an Array
Some like the arrays
$response = $client->sendCommand($command); $output = json_decode($response->getBody()->getContents(), true);
How to Convert Output to a stdClass object
Some like the objects
$response = $client->sendCommand($command); $output = json_decode($response->getBody()->getContents());
Testing
All testing is done using PHPUnit. You should be able to run phpunit in the
root directory of this project (the directory where phpunit.xml.dist is located)
and the tests will run.
If submitting a pull request or working on this library, please make sure that the tests will pass.
Change log
See CHANGELOG.md.
Contains information on releases such as what was added, changed, etc. It's good to look at to see what has changed from release to release.
Contributing
See CONTRIBUTING.md.
Various ways on contributing to this project.
Branching
master
This is the latest and greatest, it should not be used an is considered development for testing new features and functionality. This should NOT be used in a production environment.
2.x
Current production branch. All 2.x tags come off of this branch.
1.x
Deprecated, only used for bug fixes and for historical records.
License (MIT) 
Copyright (C) 2012-2018 Joshua Estes
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
nbobtc/bitcoind-php 适用场景与选型建议
nbobtc/bitcoind-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66.45k 次下载、GitHub Stars 达 164, 最近一次更新时间为 2012 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bitcoin」 「bitcoind」 「bitcoins」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nbobtc/bitcoind-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nbobtc/bitcoind-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nbobtc/bitcoind-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The BlockTrail PHP SDK, for integration of Bitcoin functionality through the BlockTrail API
Bundle that gives you a bitcoind service wrapper. Also comes with tasks that you can use on the command line.
CoinDesk Bitcoin Price Index API for Laravel
JSON-RPC client for Bitcoin core (and other altcoins based on bitcoind)
phinance, binance API PHP client
pholoniex, poloniex API PHP client
统计信息
- 总下载量: 66.45k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 167
- 点击次数: 24
- 依赖项目数: 51
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2012-11-11