PHP developer intro: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Genjix (talk | contribs)
Created page with "For the sake of this tutorial we assume an Ubuntu server running with PHP. The use case here is integrating a shopping system to accept Bitcoins. We assume some knowledge of Bitc..."
 
Genjix (talk | contribs)
No edit summary
Line 7: Line 7:
You will run Bitcoin in daemon mode. The way PHP communicates is through localhost HTTP requests. You use a library called [http://jsonrpcphp.org/ JSON-RPC] to call the various functions. It will respond back with a [http://en.wikipedia.org/wiki/Json JSON object].
You will run Bitcoin in daemon mode. The way PHP communicates is through localhost HTTP requests. You use a library called [http://jsonrpcphp.org/ JSON-RPC] to call the various functions. It will respond back with a [http://en.wikipedia.org/wiki/Json JSON object].


Bitcoins are stored internally as 64 bit integers. Because
Bitcoins are stored internally as 64 bit integers. Because PHP's JSON implementation does not provide a way to use custom types for decimal numbers, we must use an alternative branch of Bitcoin which returns all decimal amounts as strings.
 
<source lang="bash">
# install needed packages
$ sudo apt-get install build-essential libboost-all-dev libdb4.7++-dev libssl-dev libglib2.0-dev
$ git clone git://github.com/genjix/bitcoin.git
$ cd bitcoin/
$ make -f makefile.unix bitcoind
$ ./bitcoind
# wait a few seconds for it to start up
$ ./bitcoind getinfo
</source>
 
Bitcoin is now initialising and you must wait until "blocks" is at the [http://bitcoinwatch.com/ current count].

Revision as of 09:38, 21 March 2011

For the sake of this tutorial we assume an Ubuntu server running with PHP. The use case here is integrating a shopping system to accept Bitcoins. We assume some knowledge of Bitcoin and experience in PHP.

You can substitute any other language here for PHP. See the associated API reference pages for info on other languages.

Setting up Bitcoin

You will run Bitcoin in daemon mode. The way PHP communicates is through localhost HTTP requests. You use a library called JSON-RPC to call the various functions. It will respond back with a JSON object.

Bitcoins are stored internally as 64 bit integers. Because PHP's JSON implementation does not provide a way to use custom types for decimal numbers, we must use an alternative branch of Bitcoin which returns all decimal amounts as strings.

# install needed packages
$ sudo apt-get install build-essential libboost-all-dev libdb4.7++-dev libssl-dev libglib2.0-dev
$ git clone git://github.com/genjix/bitcoin.git
$ cd bitcoin/
$ make -f makefile.unix bitcoind
$ ./bitcoind
# wait a few seconds for it to start up
$ ./bitcoind getinfo

Bitcoin is now initialising and you must wait until "blocks" is at the current count.