How to check neo4j is running or not from php?

258 Views Asked by At

I want to send an email when my db is down. I don't know how to check neo4j is running or not from php. I am using neoxygen neoclient library to connect to neo4j. Is there any way around to do this ? I am using neo4j 2.3.2

2

There are 2 best solutions below

0
On

As neo4j is operated by HTTP REST interface, you just need to check if the appropriate host is reachable:

if (@fopen("http://localhost:7474/db/data/","r")) {
    // database is up
}

(assuming it's running on localhost)

2
On

a) Upgrade to graphaware neo4j-php-client, neoxygen is deprecated since months and has been ported there since more than a year.

b) You can just do a try/catch on a query :

try {
  $result = $client->run('RETURN 1 AS x');
  if (1 === $result->firstRecord()->get('x') { // db is running // }
} catch(\Exception $e) {
  // db is not running or connection cannot be made
}