Hi Bram,
Unfortunately I cannot give you help on PHP (my knowledge about this language is around 20 years old now). If you check out our Java sources [1], you will see that our ping does basically the same what you do: We try to create a connection and return true if we succeed.
Regarding logging, I would assume that it’s your freedom to decide what you do in the catch branch. I am not sure where/when Apache comes into play in your setup?
Christian
[1] https://github.com/BaseXdb/basex/blob/25f3d67/basex-core/src/main/java/org/b...
On Thu, Oct 27, 2016 at 10:22 AM, Bram Vanroy bram.vanroy1@student.kuleuven.be wrote:
Hi all
To make clear to users which corpora are currently available and which aren’t, I’m checking to see if a BaseX server instance exists and then check if a specific database exists. Testing for the database is done with db:query (as I learned through this mailinglist), but I’m not sure how I can silently test for the server in PHP.
All BaseX examples use try-catch blocks, which makes sense to catch errors that go wrong, and do something with them. If I’m not mistaken these errors are automatically logged by Apache (maybe also by other webservices). This means that if I’m only checking the existence of a server with the code below (variables left out), I will always write an error to a log file. Obviously, that is not what I want because I know that the error ‘Cannot communicate with server’ is to be expected when the server does not exist!
try { $session = new Session($dbhost, $dbport, $dbuser, $dbpwd); // db:exists returns a string 'false', still need to convert to
bool
$corpusExists =
toBoolean($session->query("db:exists('$databaseName')")->execute());
$session->close(); if ($corpusExists) { $availabilityArray[] = $databaseName; } } catch (Exception $e) { // }
This script works perfectly fine, but I do not want the errors to be logged (for this case) to prevent my error log to be full of the same error. Is there another way to test for a BaseX instance only? For instance, a way to return false when the server does not exist, I could do something like:
$session = new Session($dbhost, $dbport, $dbuser, $dbpwd);
If ($session) {
// db:exists returns a string 'false', still need to convert to
bool
$corpusExists =
toBoolean($session->query("db:exists('$databaseName')")->execute());
$session->close(); if ($corpusExists) { $availabilityArray[] = $databaseName; }
}
Thank you in advance
Bram Vanroy