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
PHP library for communication with [Neo4j](https://neo4j.com/)graph database over TCP socket with Bolt protocol specification. The Bolt documentation is available at [https://www.neo4j.com/](https://www.neo4j.com/docs/bolt/current/). This library is aimed to be low level, support all available versions and keep up with protocol messages architecture and specifications.
4
+
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 all available versions and keep up with protocol messages architecture and specifications.
<ahref='https://ko-fi.com/Z8Z5ABMLW'target='_blank'><imgheight='36'style='border:0px;height:36px;'src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3'border='0'alt='Buy Me a Coffee at ko-fi.com' /></a>
17
+
16
18
## Version support
17
19
18
-
We are trying to keep up and this library supports **Neo4j <= 4.4** with **Bolt <= 4.4**.
20
+
We are trying to keep up and this library supports **Neo4j <= 5.1** with **Bolt <= 5.1**.
Keep up with [PHP supported versions](https://www.php.net/supported-versions.php) means we are at **PHP >= 7.4**.
25
27
26
-
_If you need support for PHP < 7.4 you can use latest v3.x release. Not all new features are implement backwards._
28
+
_If you need support for PHP < 7.4 you can use latest v3.x release. Not all new features are implement backwards and this readme is updated to latest released version._
27
29
28
30
### Extensions
29
31
@@ -52,28 +54,74 @@ Run the following command in your project to install the latest applicable versi
52
54
53
55
## Usage
54
56
55
-
Concept of usage is based on Bolt messages. Available protocol methods depends on Bolt version.
57
+
Concept of usage is based on Bolt messages. 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 fetching response from the server.
58
+
59
+
Main `Bolt` class serves as Factory design pattern and it returns instance of protocol class by requested Bolt version (default is 4 latest versions). Query execution and fetching response is split in two methods. First message `run` is for sending queries. Second message `pull` is for fetching response from last executed query on database.
60
+
Response from database for Bolt message `pull` always contains n+1 rows because last entry is `success` message with meta informations.
61
+
62
+
More info about available Bolt messages: https://www.neo4j.com/docs/bolt/current/bolt/message/
| hello | Connect to database (you can use helper to provide required extra argument) | array $extra |
107
+
| run | Execute query. Response from database are meta informations. | string $statement<br/>array $parameters = []<br/>array $extra = []|
108
+
| pull | Pull result from executed query | array $extra = []|
109
+
| discard | Discard result waiting for pull | array $extra = []|
110
+
| begin | Start transaction | array $extra = []|
111
+
| commit | Commit transaction ||
112
+
| rollback | Rollback transaction ||
113
+
| reset | Send message to reset connection ||
114
+
| getVersion | Get used protocol version ||
115
+
| getResponse | Get waiting response from server ||
116
+
| getResponses | Get waiting responses from server ||
117
+
||||
118
+
| init |@see hello ||
119
+
| pullAll |@see pull ||
120
+
| discardAll |@see discard ||
121
+
122
+
Many methods accept argument called `$extra`. This argument can contain any of key-value by Bolt specification. This argument was extended during Neo4j development which means the content of it changed. You should keep in mind what version you are working with when using this argument. You can read more about extra parameter in Bolt documentation where you can look into your version and bolt message.
123
+
124
+
Annotation of methods in protocol classes contains direct link to specific version and message from mentioned documentation website.
77
125
78
126
### Transactions
79
127
@@ -87,28 +135,55 @@ _`run` executes query in auto-commit transaction if explicit transaction was not
| List | array with consecutive numeric keys from 0|
147
+
| Dictionary | object or array which is not considered as list |
148
+
| Structure | Classes implementing `IStructure` by protocol version ([docs](https://www.neo4j.com/docs/bolt/current/bolt/structure-semantics/)) |
101
149
102
150
List or dictionary can be also provided as instance of class implementing `Bolt\packstream\IPackListGenerator` or `Bolt\PackStream\IPackDictionaryGenerator`. This approach helps with memory management while working with big amount of data. To learn more you can check [performance test](https://github.com/neo4j-php/Bolt/blob/master/tests/PerformanceTest.php) or [packer test](https://github.com/neo4j-php/Bolt/blob/master/tests/PackStream/v1/PackerTest.php).
103
151
104
-
Structures Node, Relationship, UnboundRelationship and Path cannot be used as parameter. They are available only as received data from database.
152
+
Structures `Node`, `Relationship`, `UnboundRelationship` and `Path` cannot be used as parameter. They are available only as received data from database.
153
+
154
+
Server state is not available from server but we assume it. Library contains `\Bolt\helpers\ServerState` and you can get used instance of this class with `$bolt->serverState` or `$protocol->serverState` (after you call `build()`).
155
+
156
+
### Autoload
157
+
158
+
Directory `src` contains autoload file which accepts only Bolt library namespaces. Main Bolt namespace points to this directory. If you have installed this project with composer, you have to load `vendor/autoload.php`.
159
+
160
+
## Server state
161
+
162
+
If assumed server state is different than expected, library does not throw exception. This logic is silent but you can change it and if you would like to implement own logic when assumed server state is different than expected you can assign callable into class property `$serverState->expectedServerStateMismatchCallback`.
163
+
164
+
## Connection
165
+
166
+
Bolt class constructor accepts connection argument. This argument has to be instance of class which implements IConnection interface. Currently exists two predefined classes `Socket` and `StreamSocket`.
167
+
168
+
_We provide two connection classes. `Socket` was created first and it has better memory usage. `StreamSocket` was made because of need to accept TLS._
169
+
170
+
**\Bolt\connection\Socket**
171
+
172
+
This class use php extension sockets. More informations here: [https://www.php.net/manual/en/book.sockets.php](https://www.php.net/manual/en/book.sockets.php)
173
+
174
+
**\Bolt\connection\StreamSocket**
175
+
176
+
This class uses php stream functions. Which is a part of php and there is no extensions needed. More informations here: [https://www.php.net/manual/en/ref.stream.php](https://www.php.net/manual/en/ref.stream.php)
177
+
178
+
StreamSocket besides of implemented methods from interface has method to configure SSL. When you want to activate SSL you have to call method `setSslContextOptions`. This method accept array by php specification available here: [https://www.php.net/manual/en/context.ssl.php](https://www.php.net/manual/en/context.ssl.php).
179
+
180
+
_If you want to use it, you have to enable openssl php extension._
105
181
106
182
### Neo4j Aura
107
183
108
-
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use StreamSocket connection class and enable SSL.
184
+
Connecting to Aura requires encryption which is provided with SSL. To connect to Aura you have to use `StreamSocket` connection class and enable SSL.
109
185
110
186
```php
111
-
// url without neo4j+s protocol
112
187
$conn = new \Bolt\connection\StreamSocket('helloworld.databases.neo4j.io');
113
188
// enable SSL
114
189
$conn->setSslContextOptions([
@@ -119,11 +194,31 @@ $bolt = new \Bolt\Bolt($conn);
119
194
120
195
https://www.php.net/manual/en/context.ssl.php
121
196
122
-
## Another solutions
197
+
### Example on localhost database with self-signed certificate:
Connection class constructor contains `$timeout` argument. This timeout is for established socket connection. To set up timeout for establishing socket connection itself you have to set ini directive `default_socket_timeout`.
126
215
127
-
## Support
216
+
_Setting up ini directive isn't part of connection class because function `ini_set` can be disabled on production environments for security reasons._
128
217
129
-
<ahref='https://ko-fi.com/Z8Z5ABMLW'target='_blank'><imgheight='36'style='border:0px;height:36px;'src='https://cdn.ko-fi.com/cdn/kofi1.png?v=3'border='0'alt='Buy Me a Coffee at ko-fi.com' /></a>
218
+
## Another solutions
219
+
220
+
If you need simple class to cover basic functionality you can use: [neo4j-bolt-wrapper](https://packagist.org/packages/stefanak-michal/neo4j-bolt-wrapper)
221
+
222
+
When you are in need of enterprise level take a look on: [php-client](https://packagist.org/packages/laudis/neo4j-php-client)
223
+
224
+
More solutions can be found at: https://neo4j.com/developer/php/
0 commit comments