Skip to content

Commit 69facae

Browse files
Merge pull request #133 from neo4j-php/132-update-readme
Update README.md
2 parents eb665e8 + 1001515 commit 69facae

File tree

1 file changed

+71
-72
lines changed

1 file changed

+71
-72
lines changed

README.md

Lines changed: 71 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
# Bolt
44

5-
PHP library for communication with graph database over TCP socket with Bolt protocol specification. Bolt protocol was
6-
created by [Neo4j](https://neo4j.com/) and documentation is available
7-
at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support
5+
PHP library for communication with graph database over TCP socket with Bolt protocol specification. Bolt protocol was created by [Neo4j](https://neo4j.com/) and documentation is available at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support
86
all available versions and keep up with protocol messages architecture and specifications.
97

108
[![](https://img.shields.io/github/stars/stefanak-michal/Bolt)](https://github.com/neo4j-php/Bolt/stargazers)
@@ -16,28 +14,24 @@ all available versions and keep up with protocol messages architecture and speci
1614

1715
<a href='https://jb.gg/OpenSourceSupport' target='_blank'><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo (Main) logo." width="100" /></a>
1816

19-
## Version support
17+
## :label: Version support
2018

2119
We are trying to keep up and this library supports **Bolt <= 5.4**.
2220

2321
https://www.neo4j.com/docs/bolt/current/bolt-compatibility/
2422

25-
## Requirements
23+
## :white_check_mark: Requirements
2624

27-
Keep up with [PHP supported versions](https://www.php.net/supported-versions.php) means we are at **PHP^8**.
25+
This library keep up with [PHP supported versions](https://www.php.net/supported-versions.php) what means it is at **PHP^8.1**.
2826

29-
_If you need support for PHP < 7.4 you can use latest v3.x release and if you need support for PHP 7.4 you can use v5.x.
30-
Not all new features are implement backwards and this readme is updated to latest released version._
31-
32-
### Extensions
27+
### PHP Extensions
3328

3429
- [mbstring](https://www.php.net/manual/en/book.mbstring.php)
3530
- [sockets](https://www.php.net/manual/en/book.sockets.php) (optional) - Required when you use Socket connection class
3631
- [openssl](https://www.php.net/manual/en/book.openssl.php) (optional) - Required when you use StreamSocket connection
3732
class with enabled SSL
38-
- [phpunit](https://phpunit.de/) (development)
3933

40-
## Installation
34+
## :floppy_disk: Installation
4135

4236
You can use composer or download this repository from github and manually implement it.
4337

@@ -55,47 +49,14 @@ Run the following command in your project to install the latest applicable versi
5549
2. Unpack
5650
3. Copy content of `src` directory into your project
5751

58-
## Usage
52+
## :desktop_computer: Usage
5953

60-
Concept of usage is based on Bolt messages. Available protocol methods depends on Bolt version. Communication works
61-
in [pipeline](https://www.neo4j.com/docs/bolt/current/bolt/message/#pipelining) and you can chain multiple Bolt messages
62-
before fetching response from the server.
54+
Concept of usage is based on Bolt messages. Bolt messages are mapped 1:1 as protocol methods. Available protocol methods depends on Bolt version. Communication works in [pipeline](https://www.neo4j.com/docs/bolt/current/bolt/message/#pipelining) and you can chain multiple Bolt messages before consuming response from the server.
6355

64-
Main `Bolt` class serves as Factory design pattern and it returns instance of protocol class by requested Bolt version. Query execution and fetching response is split in two methods. First message `run` is for
65-
sending queries. Second message `pull` is for fetching response from last executed query on database.
66-
Response from database for Bolt message `pull` always contains n+1 rows because last entry is `success` message with
56+
Main `Bolt` class serves as Factory design pattern and it returns instance of protocol class by requested Bolt version. Basic usage consist of query execution and fetching response which is split in two methods. First message `run` is for sending queries. Second message `pull` is for fetching response from executed query on database. Response from database for Bolt message `pull` always contains n+1 rows because last entry is `success` message with
6757
meta informations.
6858

69-
More info about available Bolt messages: https://www.neo4j.com/docs/bolt/current/bolt/message/
70-
71-
### Example
72-
73-
```php
74-
// Create connection class and specify target host and port.
75-
$conn = new \Bolt\connection\Socket('127.0.0.1', 7687);
76-
// Create new Bolt instance and provide connection object.
77-
$bolt = new \Bolt\Bolt($conn);
78-
// Set requested protocol versions
79-
$bolt->setProtocolVersions(5.1, 5, 4.4);
80-
// Build and get protocol version instance which creates connection and executes handshake.
81-
$protocol = $bolt->build();
82-
// Connect and login into database
83-
$protocol->hello();
84-
$protocol->logon(['scheme' => 'basic', 'principal' => 'neo4j', 'credentials' => 'neo4j']);
85-
86-
// Pipeline two messages. One to execute query with parameters and second to pull records.
87-
$protocol
88-
->run('RETURN $a AS num, $b AS str', ['a' => 123, 'b' => 'text'])
89-
->pull();
90-
91-
// Fetch waiting server responses for pipelined messages.
92-
foreach ($protocol->getResponses() as $response) {
93-
// $response is instance of \Bolt\protocol\Response.
94-
// First response is SUCCESS message for RUN message.
95-
// Second response is RECORD message for PULL message.
96-
// Third response is SUCCESS message for PULL message.
97-
}
98-
```
59+
:information_source: More info about available Bolt messages: https://www.neo4j.com/docs/bolt/current/bolt/message/
9960

10061
### Available methods
10162

@@ -132,12 +93,12 @@ foreach ($protocol->getResponses() as $response) {
13293
| pullAll | @see pull | |
13394
| discardAll | @see discard | |
13495

135-
Many methods accept argument called `$extra`. This argument can contain any of key-value by Bolt specification. This
96+
Multiple methods accept argument called `$extra`. This argument can contain any of key-value by Bolt specification. This
13697
argument was extended during Neo4j development which means the content of it changed. You should keep in mind what
13798
version you are working with when using this argument. You can read more about extra parameter in Bolt documentation
13899
where you can look into your version and bolt message.
139100

140-
Annotation of methods in protocol classes contains direct link to specific version and message from mentioned
101+
:information_source: Annotation of methods in protocol classes contains direct link to specific version and message from mentioned
141102
documentation website.
142103

143104
### Authentification
@@ -179,51 +140,81 @@ of data. To learn more you can
179140
check [performance test](https://github.com/neo4j-php/Bolt/blob/master/tests/PerformanceTest.php)
180141
or [packer test](https://github.com/neo4j-php/Bolt/blob/master/tests/PackStream/v1/PackerTest.php).
181142

182-
Structures `Node`, `Relationship`, `UnboundRelationship` and `Path` cannot be used as parameter. They are available only
143+
:warning: Structures `Node`, `Relationship`, `UnboundRelationship` and `Path` cannot be used as parameter. They are available only
183144
as received data from database.
184145

185-
Server state is not available from server but we assume it. Library contains `\Bolt\helpers\ServerState` and you can get
186-
used instance of this class with `$bolt->serverState` or `$protocol->serverState` (after you call `build()`).
146+
### Example
147+
148+
```php
149+
// Choose and create connection class and specify target host and port.
150+
$conn = new \Bolt\connection\Socket('127.0.0.1', 7687);
151+
// Create new Bolt instance and provide connection object.
152+
$bolt = new \Bolt\Bolt($conn);
153+
// Set requested protocol versions ..you can add up to 4 versions
154+
$bolt->setProtocolVersions(5.4);
155+
// Build and get protocol version instance which creates connection and executes handshake.
156+
$protocol = $bolt->build();
157+
158+
// Initialize communication with database
159+
$response = $protocol->hello()->getResponse();
160+
// verify $response for successful initialization
161+
162+
// Login into database
163+
$response = $protocol->logon(['scheme' => 'basic', 'principal' => 'neo4j', 'credentials' => 'neo4j'])->getResponse();
164+
// verify $response for successful login
165+
166+
// Pipeline two messages. One to execute query with parameters and second to pull records.
167+
$protocol
168+
->run('RETURN $a AS num, $b AS str', ['a' => 123, 'b' => 'text'])
169+
->pull();
170+
171+
// Fetch waiting server responses for pipelined messages.
172+
foreach ($protocol->getResponses() as $response) {
173+
// $response is instance of \Bolt\protocol\Response.
174+
// First response is SUCCESS message for RUN message.
175+
// Second response is RECORD message for PULL message.
176+
// Third response is SUCCESS message for PULL message.
177+
}
178+
```
187179

188180
### Autoload
189181

190182
Directory `src` contains autoload file which accepts only Bolt library namespaces. Main Bolt namespace points to this
191183
directory. If you have installed this project with composer, you have to load `vendor/autoload.php`.
192184

193-
## Server state
194-
195-
If assumed server state is different than expected, library does not throw exception. This logic is silent but you can
196-
change it and if you would like to implement own logic when assumed server state is different than expected you can
197-
assign callable into class property `$serverState->expectedServerStateMismatchCallback`.
185+
## :vertical_traffic_light: Server state
198186

199-
## Connection
187+
Server state is not reported by server but it is evaluated by received response. You can access current state through property `$protocol->serverState`. This property is updated with every call `getResponse(s)`.
200188

201-
Bolt class constructor accepts connection argument. This argument has to be instance of class which implements
202-
IConnection interface. Currently exists two predefined classes `Socket` and `StreamSocket`.
189+
## :chains: Connection
203190

204-
_We provide two connection classes. `Socket` was created first and it has better memory usage. `StreamSocket` was made
205-
because of need to accept TLS._
191+
Bolt class constructor accepts connection argument. This argument has to be instance of class which implements IConnection interface. Library offers few options.
206192

207193
**\Bolt\connection\Socket**
208194

209-
This class use php extension sockets. More informations
195+
This class use php extension sockets and has better memory usage. More informations
210196
here: [https://www.php.net/manual/en/book.sockets.php](https://www.php.net/manual/en/book.sockets.php)
211197

212198
**\Bolt\connection\StreamSocket**
213199

214200
This class uses php stream functions. Which is a part of php and there is no extensions needed. More informations
215201
here: [https://www.php.net/manual/en/ref.stream.php](https://www.php.net/manual/en/ref.stream.php)
216202

217-
StreamSocket besides of implemented methods from interface has method to configure SSL. When you want to activate SSL
203+
StreamSocket besides of implemented methods from interface has method to configure SSL. SSL option requires php extension openssl. When you want to activate SSL
218204
you have to call method `setSslContextOptions`. This method accept array by php specification available
219205
here: [https://www.php.net/manual/en/context.ssl.php](https://www.php.net/manual/en/context.ssl.php).
220206

221-
_If you want to use it, you have to enable openssl php extension._
207+
**\Bolt\connection\PStreamSocket**
208+
209+
This class extends StreamSocket and adds support for persistent connections. Upon reuse of connection remaining buffer is consumed and message RESET is automatically sent. PHP is stateless therefore using this connection class requires storing meta information about active TCP connection. Default storage is `\Bolt\helper\FileCache` which you can change with method `setCache` (PSR-16 Simple Cache).
210+
211+
:warning: If your system reuse persistent connection and meta information about it was lost for some reason, your attemt to connect will end with ConnectionTimeoutException. Repeated attempt to connect will succeed.
212+
213+
## :lock: SSL
222214

223215
### Neo4j Aura
224216

225-
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use `StreamSocket`
226-
connection class and enable SSL.
217+
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use `StreamSocket` connection class and enable SSL.
227218

228219
```php
229220
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
@@ -251,18 +242,18 @@ $conn->setSslContextOptions([
251242
$bolt = new \Bolt\Bolt($conn);
252243
```
253244

254-
You can also take a look at my article on how to implement SSL for Neo4j running on localhost
245+
:bookmark: You can also take a look at my article on how to implement SSL for Neo4j running on localhost
255246
at [Neo4j and self signed certificate](https://ko-fi.com/post/Neo4j-and-self-signed-certificate-on-Windows-S6S2I0KQT).
256247

257-
### Timeout
248+
## :stopwatch: Timeout
258249

259250
Connection class constructor contains `$timeout` argument. This timeout is for established socket connection. To set up
260251
timeout for establishing socket connection itself you have to set ini directive `default_socket_timeout`.
261252

262253
_Setting up ini directive isn't part of connection class because function `ini_set` can be disabled on production
263254
environments for security reasons._
264255

265-
## Another solutions
256+
## :pushpin: More solutions
266257

267258
If you need simple class to cover basic functionality you can
268259
use: [neo4j-bolt-wrapper](https://packagist.org/packages/stefanak-michal/neo4j-bolt-wrapper)
@@ -273,3 +264,11 @@ on: [php-client](https://packagist.org/packages/laudis/neo4j-php-client)
273264
PDO implementation is available at [pdo-bolt](https://github.com/stefanak-michal/pdo-bolt)
274265

275266
More informations can be found at: https://neo4j.com/developer/php/
267+
268+
## :recycle: Old versions
269+
270+
If you need support for end-of-life PHP versions, here is a short info list. Not all new features are implement backwards and this readme is updated to latest released version.
271+
272+
* PHP < 7.4 - v3.x
273+
* PHP 7.4 - v5.x
274+
* PHP 8.0 - v6.x

0 commit comments

Comments
 (0)