0

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

iit2011081
  • 742
  • 8
  • 26

2 Answers2

0

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)

Ivan Skalauh
  • 319
  • 2
  • 12
0

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
}
Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36