Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

!!! Question !!! about catching Exceptions #94

Closed
sarral opened this issue Jul 23, 2012 · 4 comments
Closed

!!! Question !!! about catching Exceptions #94

sarral opened this issue Jul 23, 2012 · 4 comments

Comments

@sarral
Copy link

sarral commented Jul 23, 2012

Trying to trap when I can't connect to the cluster.

Thank you for your help.

I have looked everywhere (except where an example is, haha) to find an example
I'm kinda new to PHP, but experienced programmer.

I'm going to try this as a script, without using a Class

class CassCore
{
...

function __construct() {
try {
$this->rCONN = new ConnectionPool(self::KS, $this->servers);
}
catch( NoServerAvailable $e ) {
echo "No Connection to Cluster\n";
die("FOUND EXCEPTION\n");
}
catch( phpcassa\Connection\NoServerAvailable $e ) {
echo "No Connection to Cluster\n";
die("FOUND EXCEPTION\n");
}
// Connect to CFs
......
return;
}

and what i receive:

Error connecting to 191.168.1.50: TException: TSocket: Could not connect to 191.168.1.50:9160 (Connection timed out [110])
Error connecting to 191.168.1.101: TException: TSocket: Could not connect to 191.168.1.101:9160 (Connection timed out [110])
Error connecting to 191.168.1.50: TException: TSocket: Could not connect to 191.168.1.50:9160 (Connection timed out [110])
Error connecting to 191.168.1.101: TException: TSocket: Could not connect to 191.168.1.101:9160 (Connection timed out [110])

Fatal error: Uncaught exception 'phpcassa\Connection\NoServerAvailable' with message 'An attempt was made to connect to every server twice, but all attempts failed. The last error was: TException:TSocket: Could not connect to 191.168.1.101:9160 (Connection timed out [110])' in /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php:138

Stack trace:
#0 /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(163): phpcassa\Connection\ConnectionPool->make_conn()
#1 /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(257): phpcassa\Connection\ConnectionPool->get()
#2 /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(192): phpcassa\Connection\ConnectionPool->call('describe_keyspa...', 'ip_store')
#3 /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/ColumnFamily.php(193): phpcassa\Connection\ConnectionPool->describe_keyspace()
#4 /home/shaun/Documents/Cassandra/CassCore.php(67): phpcassa\ColumnFamily->__const in /home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php on line 138

@sarral
Copy link
Author

sarral commented Jul 23, 2012

nevermind.... figured it out.

try {
$this->rCF_ip = new ColumnFamily($this->rCONN, self::CF_ip);
$this->rCF_det = new ColumnFamily($this->rCONN, self::CF_det);
}

catch( phpcassa\Connection\NoServerAvailable $e ) {
echo "4: No Connection to Cluster\n";
die("FOUND EXCEPTION\n");
}

@sarral
Copy link
Author

sarral commented Jul 23, 2012

FYI for other users.

@sarral sarral closed this as completed Jul 23, 2012
@thobbs
Copy link
Owner

thobbs commented Jul 26, 2012

Are you using the autoloader (autoload.php)? If so, try adding 'use
phpcassa\Connection\NoServerAvailable;' to the top of your script, and your
first catch block should work.

On Mon, Jul 23, 2012 at 5:06 PM, Shaun Arral <
reply@reply.github.com

wrote:

Trying to trap when I can't connect to the cluster.

Thank you for your help.

I have looked everywhere (except where an example is, haha) to find an
example
I'm kinda new to PHP, but experienced programmer.

I'm going to try this as a script, without using a Class

class CassCore
{
...

function __construct() {
try {
$this->rCONN = new ConnectionPool(self::KS, $this->servers);
}
catch( NoServerAvailable $e ) {
echo "No Connection to Cluster\n";
die("FOUND EXCEPTION\n");
}
catch( phpcassa\Connection\NoServerAvailable $e ) {
echo "No Connection to Cluster\n";
die("FOUND EXCEPTION\n");
}
// Connect to CFs
......
return;
}

and what i receive:

Error connecting to 191.168.1.50: TException: TSocket: Could not connect
to 191.168.1.50:9160 (Connection timed out [110])
Error connecting to 191.168.1.101: TException: TSocket: Could not connect
to 191.168.1.101:9160 (Connection timed out [110])
Error connecting to 191.168.1.50: TException: TSocket: Could not connect
to 191.168.1.50:9160 (Connection timed out [110])
Error connecting to 191.168.1.101: TException: TSocket: Could not connect
to 191.168.1.101:9160 (Connection timed out [110])

Fatal error: Uncaught exception 'phpcassa\Connection\NoServerAvailable'
with message 'An attempt was made to connect to every server twice, but all
attempts failed. The last error was: TException:TSocket: Could not connect
to 191.168.1.101:9160 (Connection timed out [110])' in
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php:138

Stack trace:

#0
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(163):
phpcassa\Connection\ConnectionPool->make_conn()

#1
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(257):
phpcassa\Connection\ConnectionPool->get()

#2
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php(192):
phpcassa\Connection\ConnectionPool->call('describe_keyspa...', 'ip_store')

#3
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/ColumnFamily.php(193):
phpcassa\Connection\ConnectionPool->describe_keyspace()

#4 /home/shaun/Documents/Cassandra/CassCore.php(67):
phpcassa\ColumnFamily->__const in
/home/shaun/Documents/Cassandra/phpcass/lib/phpcassa/Connection/ConnectionPool.php
on line 138


Reply to this email directly or view it on GitHub:
#94

Tyler Hobbs
DataStax http://datastax.com/

@sarral
Copy link
Author

sarral commented Jul 27, 2012

Yes.

require_once('../phpcass/lib/autoload.php');

It's probably better to catch early (ConnectionPool) rather than what I figured out to do: Catch on ColumnFamily init.

my second comment did work. Going to do your suggestion.

Thanks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants