PHP can write the blockchain; you can use "class Block {public Hash value of the previous block; public Hash value of the current block; public timestamp generated by the block; public data saved in the block ;}" code to define the block.
The operating environment of this article: Windows 10 system, PHP version 7.1, Dell G3 computer.
PHP can write blockchain.
Use PHP code to define blocks:
class Block { public $prevHash; public $hash; public $timeStamp; public $data; }
prevHash: Hash value of the previous block;
hash: Hash value of the current block;
timeStamp: timestamp generated by the block;
data: data saved in the block;
prevHash, hash and timeStamp fields are called block headers in the blockchain , the hash value of the block is calculated using the SHA-256 algorithm.
The actual use and significance of blockchain:
Blockchain is a decentralized distributed ledger. What decentralization means is that there is no center, or everyone can be the center. This is different from the traditional centralization method. Distributed ledger means that data is not only stored on each node, but each node copies and shares the data of the entire ledger.
In addition, blockchain also has the characteristics of disintermediation and information transparency. For example, if we shop on Taobao, the fee we pay after placing the order is transferred to Alipay first. The money will not be transferred to the seller's account until we receive the express delivery and confirm receipt of the goods. In the blockchain, buyers and sellers can trade directly without any platform as a third-party certification agency to participate.
The system will publish the transaction information of buyers and sellers in the form of broadcast. All hosts will record and back up transaction data after receiving the information. If an error occurs in the orders produced by one machine, it will not affect the backup data of other machines.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Can PHP write blockchain?. For more information, please follow other related articles on the PHP Chinese website!