anshu-krishna/neo4j-bolt
Composer 安装命令:
composer require anshu-krishna/neo4j-bolt
包简介
PHP driver for Bolt protocol for communication with Neo4j graph database over TCP
README 文档
README
PHP driver for Bolt protocol for communication with Neo4j graph database over TCP
Installation:
composer require anshu-krishna/neo4j-bolt
Requirements:
- PHP >= 8.1
- Neo4j (with Bolt version 4.4, 4.3, 4.2 or 4.1)
Note: All examples use the Neo4j 'Example Movie Database'
Example:
require_once "vendor/autoload.php"; use Krishna\Neo4j\{AuthToken, BoltMaker}; use Krishna\Neo4j\Protocol\Reply\Success; // Create Bolt $bolt = (new BoltMaker( auth: AuthToken::basic('neo4j', 'neo4j') ))->makeBolt(); echo 'Running Bolt version:', $bolt::VERSION, '<br>'; // Run Query $run = $bolt->query(<<<CYPHER match (p:Person)-[a:ACTED_IN]->(m:Movie) return p as person, a.roles as roles, {title: m.title, year: m.released} as movie limit 2 CYPHER); if(!$run instanceof Success) { echo 'Query Error: ', $run->message; exit(0); } echo <<<HTML <table border="1"> <tr> <th>Person</th> <th>Born</th> <th>Role(s)</th> <th>Movie</th> <th>Released</th> </tr> HTML; // Pull results foreach($bolt->pull() as $i) { $roles = implode(', ', $i->roles); echo <<<"ROW" <tr> <td>{$i->person->properties['name']}</td> <td>{$i->person->properties['born']}</td> <td>{$roles}</td> <td>{$i->movie['title']}</td> <td>{$i->movie['year']}</td> </tr> ROW; } echo '</table>';
For specifc BOLT version:
Use the useVersion() in BoltMaker to set upto 4 versions in order of preference.
$bolt = (new BoltMaker(auth: AuthToken::basic('neo4j', 'neo4j'))) ->useVersion(E_Version::V4_2, E_Version::V4_1) ->makeBolt(); var_dump($bolt::VERSION);
Debug Logging:
Pass a Logger object in BoltMaker for protocol debug logs.
$bolt = (new BoltMaker( auth: AuthToken::basic('neo4j', 'neo4j'), logger: new Logger(rowSize: 20) ))->makeBolt();
Output:
Write [Handshake]:
60 60 b0 17 00 00 04 04 00 00 03 04 00 00 02 04 00 00 01 04
Read [Handshake]:
00 00 04 04
Write [Hello]:
00 01 b1 00 01 01 a4 8a 75 73 65 72 5f 61 67 65 6e 74 89 4b
42 6f 6c 74 2f 31 2e 30 86 73 63 68 65 6d 65 85 62 61 73 69
63 89 70 72 69 6e 63 69 70 61 6c 85 6e 65 6f 34 6a 8b 63 72
65 64 65 6e 74 69 61 6c 73 85 6e 65 6f 34 6a 00 00
Read [Hello = Success]:
b1 70 a3 86 73 65 72 76 65 72 8b 4e 65 6f 34 6a 2f 34 2e 34
2e 35 8d 63 6f 6e 6e 65 63 74 69 6f 6e 5f 69 64 87 62 6f 6c
74 2d 31 38 85 68 69 6e 74 73 a0
Write [Goodbye]:
00 01 b0 00 01 02 00 00
To start logging after creating a Bolt protocol:
$bolt = (new BoltMaker( auth: AuthToken::basic('neo4j', 'neo4j') ))->makeBolt(); // Start logging $bolt->logger = new Logger; // Execute quries here // Stop logging $bolt->logger = null;
Protocol functions:
-
Run a query
function query( string $query, array $parameters = [], bool $autoResetOnFaiure = true, array $bookmarks = [], int $tx_timeout = -1, ?array $tx_metadata = null, bool $readMode = false, ?string $db = null ): I_Reply;
-
Pull results
function pull(int $count = -1, int $qid = -1); /* qid is query id */
-
Disconnect
function disconnect(): void;
-
Reset connection
function reset(): I_Reply;
-
Start a transaction
function beginTransaction( array $bookmarks = [], int $tx_timeout = -1, ?array $tx_metadata = null, bool $readMode = false, ?string $db = null ): I_Reply;
-
Commit transaction
function commit(): I_Reply;
-
Rollback transaction
function rollback(): I_Reply;
-
Get last query metadata
function getQueryMeta(): ?I_Reply;
-
Check if last query was valid
function queryValid(): bool;
-
Check if last query has more results
function moreResults(): bool;
-
Discard results
function discard(int $count = -1, int $qid = -1): ?I_Reply; /* qid is query id */
Only in Bolt >= 4.3
- Send route message
function route(array $routing, array $bookmarks, ?string $db = null): I_Reply;
anshu-krishna/neo4j-bolt 适用场景与选型建议
anshu-krishna/neo4j-bolt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 09 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「Socket」 「neo4j」 「bolt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 anshu-krishna/neo4j-bolt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anshu-krishna/neo4j-bolt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 anshu-krishna/neo4j-bolt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Symfony integration for Neo4j
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A PSR-7 compatible library for making CRUD API endpoints
A PHP Object Graph Mapper for Tinkerpop 3+ compatible Graph Databases (JanusGraph, Neo4j, etc.) that allows you to persist data and run gremlin queries.
统计信息
- 总下载量: 20
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-01