Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client enhancement #184

Merged
merged 11 commits into from
Sep 21, 2023
58 changes: 35 additions & 23 deletions .github/workflows/integration-test-cluster-neo4j-5.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
tests:
runs-on: ubuntu-latest
env:
CONNECTION: neo4j://neo4j:testtest@localhost:7688
name: "Running on PHP 8.0 with a Neo4j 5.6.0-enterprise cluster"
CONNECTION: neo4j://neo4j:testtest@localhost:7687
name: "Running on PHP 8.0 with a Neo4j 5.10-enterprise cluster"

steps:
- uses: actions/checkout@v2
Expand All @@ -38,72 +38,84 @@ jobs:

services:
server1:
image: neo4j:5.6.0-enterprise
image: neo4j:5.10-enterprise
ports:
- 7688:7688
- 7475:7475
- 7687:7687
- 7473:7473
- 7474:7474
env:
NEO4J_initial_server_mode__constraint: PRIMARY
NEO4J_dbms_cluster_discovery_endpoints: server1:5000,server2:5000,server3:5000
NEO4J_ACCEPT_LICENSE_AGREEMENT: yes
NEO4j_server_bolt_advertised_address: localhost:7688
NEO4j_server_http_advertised_address: localhost:7478
NEO4j_server_bolt_advertised_address: localhost:7687
NEO4j_server_http_advertised_address: localhost:7474
NEO4J_PLUGINS: '["apoc"]'
NEO4J_AUTH: neo4j/testtest
options: >-
--hostname server1
--health-cmd "wget -q --method=HEAD http://localhost:7474 || exit 1"
--health-start-period "60s"
--health-interval "30s"
--health-timeout "15s"
--health-retries "5"
server2:
image: neo4j:5.6.0-enterprise
image: neo4j:5.10-enterprise
ports:
- 7689:7689
- 7476:7476
- 8687:7687
- 8473:7473
- 8474:7474
env:
NEO4J_initial_server_mode__constraint: PRIMARY
NEO4J_dbms_cluster_discovery_endpoints: server1:5000,server2:5000,server3:5000
NEO4J_ACCEPT_LICENSE_AGREEMENT: yes
NEO4j_server_bolt_advertised_address: localhost:7689
NEO4j_server_http_advertised_address: server2:7476
NEO4j_server_bolt_advertised_address: localhost:8687
NEO4j_server_http_advertised_address: localhost:8474
NEO4J_PLUGINS: '["apoc"]'
NEO4J_AUTH: neo4j/testtest
options: >-
--hostname server2
--health-cmd "wget -q --method=HEAD http://localhost:7474 || exit 1"
--health-start-period "60s"
--health-interval "30s"
--health-timeout "15s"
--health-retries "5"
server3:
image: neo4j:5.6.0-enterprise
image: neo4j:5.10-enterprise
ports:
- 7690:7690
- 7477:7477
- 9474:7474
- 9473:7473
- 9687:7687
env:
NEO4J_initial_server_mode__constraint: PRIMARY
NEO4J_dbms_cluster_discovery_endpoints: server1:5000,server2:5000,server3:5000
NEO4J_ACCEPT_LICENSE_AGREEMENT: yes
NEO4j_server_bolt_advertised_address: localhost:7690
NEO4j_server_http_advertised_address: server3:7477
NEO4j_server_bolt_advertised_address: localhost:9687
NEO4j_server_http_advertised_address: localhost:9474
NEO4J_PLUGINS: '["apoc"]'
NEO4J_AUTH: neo4j/testtest
options: >-
--hostname server3
--health-cmd "wget -q --method=HEAD http://localhost:7474 || exit 1"
--health-start-period "60s"
--health-interval "30s"
--health-timeout "15s"
--health-retries "5"
read-server4:
image: neo4j:5.6.0-enterprise
image: neo4j:5.10-enterprise
ports:
- 7691:7691
- 7478:7478
- 10474:7474
- 10473:7473
- 10687:7687
env:
NEO4J_initial_server_mode__constraint: PRIMARY
NEO4J_initial_server_mode__constraint: SECONDARY
NEO4J_dbms_cluster_discovery_endpoints: server1:5000,server2:5000,server3:5000
NEO4J_ACCEPT_LICENSE_AGREEMENT: yes
NEO4j_server_bolt_advertised_address: localhost:7691
NEO4j_server_http_advertised_address: localhost:7478
NEO4j_server_bolt_advertised_address: localhost:10687
NEO4j_server_http_advertised_address: localhost:10474
NEO4J_PLUGINS: '["apoc"]'
NEO4J_AUTH: neo4j/testtest
options: >-
--hostname read-server4
--health-cmd "wget -q --method=HEAD http://localhost:7474 || exit 1"
--health-start-period "60s"
--health-interval "30s"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/integration-test-single-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
name: "Running on PHP 8.2 with a Neo4j 5.5 instance connecting over all available protocols"
name: "Running on PHP 8.2 with a Neo4j 5 instance connecting over all available protocols"

services:
neo4j:
image: neo4j:5.5
image: neo4j:5
env:
NEO4J_AUTH: neo4j/testtest
NEO4JLABS_PLUGINS: '["apoc"]'
Expand Down
112 changes: 60 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@

## See the driver in action

An example project exists on the [neo4j github](https://github.com/neo4j-examples/movies-neo4j-php-client). It uses Slim and neo4j-php-client to build an API for the classic movie's example of neo4j.
- [An implementation of the class movie database](https://github.com/neo4j-examples/movies-neo4j-php-client). It uses Slim and neo4j-php-client to build an API for the classic movie's example of neo4j.
- [An complete implementation of the realworld example](https://github.com/neo4j-examples/php-laravel-neo4j-realworld-example). It uses Laravel to implement the [real world example](https://github.com/gothinkster/realworld) project, _the mother of all demo apps_.
- [The friends api](https://github.com/neo4j-examples/friends-php-client) for the world's most corny example project leveraging the power of Neo4j.

### Follow along on the livestream
For some more detailed write-ups you can refer to these blogposts:

We are currently running a biweekly neo4j + laravel livestream were we are building the RealWorld example app.
- [How to build a JSON RESTful API with Neo4j, PHP and Open API](https://medium.com/neo4j/how-to-build-a-json-restful-api-with-neo4j-php-and-openapi-e45bf0a8956)
- [Building a Web App with Neo4j, AuraDB and PHP](https://medium.com/neo4j/building-a-web-app-with-neo4j-auradb-and-php-990deca0d213)
- [Connect to Neo4j with PHP](https://medium.com/neo4j/connect-to-neo4j-with-php-e10e24afedff)
- [Enterprise level PHP and Neo4j](https://medium.com/neo4j/enterprise-level-php-and-neo4j-e467a789e6b4)

The [github repostiory can be found here](https://github.com/neo4j-examples/php-laravel-neo4j-realworld-example), there are also [recordings](https://www.youtube.com/playlist?list=PL9Hl4pk2FsvViI9wmdDpRS7tZ8V6j4uJs). The live stream usually starts at 5 PM Brussels time on Wednesday, but you can [follow Florent on twitter](https://twitter.com/fbiville) for live updates in case the schedule changes.
Or watch any of these [videos](https://www.youtube.com/watch?v=qwz5XVtbfSY&list=PL9Hl4pk2FsvViI9wmdDpRS7tZ8V6j4uJs).

## Start your driving experience in three easy steps

Expand Down Expand Up @@ -70,10 +75,47 @@ echo $result; // echos 'z'
## Decide how to send your Cypher queries

You can control the driver using three different approaches:
- *Transaction functions* (recommended and portable)
- *Auto committed queries* (easiest and most intuitive)
- *Transaction functions* (most portable)
- *Unmanaged transactions* (for the highest degree of control)


### Auto committed queries

Auto committed queries are the most straightforward and most intuitive but have many drawbacks when running complex business logic or within a high availability environment.

#### Run a simple cypher query

```php
$client->run(
'MERGE (user {email: $email})', //The query is a required parameter
['email' => '[email protected]'], //Requests can be optionally added
'backup' //The default connection can be overridden
);
```

#### Run a statement object:

```php
use Laudis\Neo4j\Databags\Statement;

$statement = new Statement('MERGE (user {email: $email})', ['email' => '[email protected]']);
$client->runStatement($statement, 'default');
```

#### Running multiple queries at once

The `runStatements` method will run all the statements at once. This method is an essential tool to reduce the number of database calls, especially when using the HTTP protocol.

```php
use Laudis\Neo4j\Databags\Statement;

$results = $client->runStatements([
Statement::create('MATCH (x) RETURN x LIMIT 100'),
Statement::create('MERGE (x:Person {email: $email})', ['email' => '[email protected]'])
]);
```

### Transaction functions

Transaction functions are the **de facto** standard when using the driver. It is the most portable as it is resistant to a lot of the pitfalls when first developing with high availability solutions such as [Neo4j aura](https://neo4j.com/blog/neo4j-aura-enterprise-ga-release/) or a [cluster](https://neo4j.com/docs/operations-manual/current/clustering/).
Expand Down Expand Up @@ -116,42 +158,6 @@ $client->writeTransaction(static function (TransactionInterface $tsx) use ($id)
$externalCounter->incrementNodesCreated();
```

### Auto committed queries

Auto committed queries are the most straightforward and most intuitive but have many drawbacks when running complex business logic or within a high availability environment.

#### Run a simple cypher query

```php
$client->run(
'MERGE (user {email: $email})', //The query is a required parameter
['email' => '[email protected]'], //Requests can be optionally added
'backup' //The default connection can be overridden
);
```

#### Run a statement object:

```php
use Laudis\Neo4j\Databags\Statement;

$statement = new Statement('MERGE (user {email: $email})', ['email' => '[email protected]']);
$client->runStatement($statement, 'default');
```

#### Running multiple queries at once

The `runStatements` method will run all the statements at once. This method is an essential tool to reduce the number of database calls, especially when using the HTTP protocol.

```php
use Laudis\Neo4j\Databags\Statement;

$results = $client->runStatements([
Statement::create('MATCH (x) RETURN x LIMIT 100'),
Statement::create('MERGE (x:Person {email: $email})', ['email' => '[email protected]'])
]);
```

### Unmanaged transactions

If you need lower-level access to the drivers' capabilities, then you want unmanaged transactions. They allow for completely controllable commits and rollbacks.
Expand Down Expand Up @@ -261,22 +267,24 @@ $client->run('MATCH (x) WHERE x.slug in $listOrMap RETURN x', ['listOrMap' => []

### Neo4j Version Support

| **Version** | **Tested** |
|-------------|-------------|
| 3.0 + | Yes |
| 4.0 + | Yes |
| **Version** | **Tested** |
|-------------|------------|
| 3.0 + | Yes |
| 4.0 + | Yes |
| 5.0 + | Yes |

### Neo4j Feature Support

| **Feature** | **Supported?** |
|----------------------|----------------|
| Authentication | Yes |
| Transactions | Yes |
| Http Protocol | Yes |
| Bolt Protocol | Yes |
| Cluster | Yes |
| Aura | Yes |
| Jolt Protocol | Roadmap |
| Authentication | Yes |
| Transactions | Yes |
| Http Protocol | Yes |
| Bolt Protocol | Yes |
| Cluster | Yes |
| Aura | Yes |
| Jolt Protocol | Yes |
| Bookmarks | Yes |

## In-depth requirements

Expand Down
Loading
Loading