You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+69-76Lines changed: 69 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,7 @@
2
2
3
3
# Bolt
4
4
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
8
6
all available versions and keep up with protocol messages architecture and specifications.
@@ -16,28 +14,24 @@ all available versions and keep up with protocol messages architecture and speci
16
14
17
15
<ahref='https://jb.gg/OpenSourceSupport'target='_blank'><imgsrc="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png"alt="JetBrains Logo (Main) logo."width="100" /></a>
18
16
19
-
## Version support
17
+
## :label:Version support
20
18
21
19
We are trying to keep up and this library supports **Bolt <= 5.4**.
-[sockets](https://www.php.net/manual/en/book.sockets.php) (optional) - Required when you use Socket connection class
36
31
-[openssl](https://www.php.net/manual/en/book.openssl.php) (optional) - Required when you use StreamSocket connection
37
32
class with enabled SSL
38
-
-[phpunit](https://phpunit.de/) (development)
39
33
40
-
## Installation
34
+
## :floppy_disk:Installation
41
35
42
36
You can use composer or download this repository from github and manually implement it.
43
37
@@ -55,52 +49,14 @@ Run the following command in your project to install the latest applicable versi
55
49
2. Unpack
56
50
3. Copy content of `src` directory into your project
57
51
58
-
## Usage
52
+
## :desktop_computer:Usage
59
53
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.
63
55
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
67
57
meta informations.
68
58
69
-
More info about available Bolt messages: https://www.neo4j.com/docs/bolt/current/bolt/message/
70
-
71
-
### Example
72
-
73
-
```php
74
-
// Choose and 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 ..you can add up to 4 versions
79
-
$bolt->setProtocolVersions(5.4);
80
-
// Build and get protocol version instance which creates connection and executes handshake.
// 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
+
```
179
+
190
180
### Autoload
191
181
192
182
Directory `src` contains autoload file which accepts only Bolt library namespaces. Main Bolt namespace points to this
193
183
directory. If you have installed this project with composer, you have to load `vendor/autoload.php`.
194
184
195
-
## Server state
185
+
## :vertical_traffic_light:Server state
196
186
197
-
Server state is not reported by server but it is evaluated by received response. You can access current state through `$protocol->serverState`. This property is updated with every call `getResponse(s)`.
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)`.
198
188
199
-
## Connection
189
+
## :chains:Connection
200
190
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`.
203
-
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.
206
192
207
193
**\Bolt\connection\Socket**
208
194
209
-
This class use php extension sockets. More informations
195
+
This class use php extension sockets and has better memory usage. More informations
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
218
204
you have to call method `setSslContextOptions`. This method accept array by php specification available
_If you want to use it, you have to enable openssl php extension._
222
-
223
207
**\Bolt\connection\PStreamSocket**
224
208
225
-
This class extends StreamSocket and adds support for persistent connections.
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).
226
210
227
-
todo add more description, maybe copy it from class annotation
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
228
214
229
215
### Neo4j Aura
230
216
231
-
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use `StreamSocket`
232
-
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.
233
218
234
219
```php
235
220
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
@@ -279,3 +264,11 @@ on: [php-client](https://packagist.org/packages/laudis/neo4j-php-client)
279
264
PDO implementation is available at [pdo-bolt](https://github.com/stefanak-michal/pdo-bolt)
280
265
281
266
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.
0 commit comments