Steve Rosenhamer Thu Jul 08 22:15:46 -0400 2010

Subject: reconnecting to lost server connection

Just wondering if there was a way to re-establish a database server connection in the event that it is lost. Working on some daemon processes and I need to able to keep them up and running. I am able to catch and identify the appropriate exception, however, can not find any documentation that would lead me to believe there is anyway to reconnect...

Any suggestions are greatly appreciated.

thanks.


Kien La Fri Jul 09 20:33:16 -0400 2010
Steve Rosenhamer Fri Jul 09 23:50:16 -0400 2010

Oh so close.... From what I can tell, it reconnects to the server and hooks that up to the model where called... for example, YouModel::reestablish_connection() will make queries attached to YourModel work, however, any associations still appear to throw the "server has gone away" exception from Connection.php on line 276...

Thanks you so much for working on this. php-activerecord is a great ORM

Kien La Mon Jul 12 20:35:57 -0400 2010

Add a call to clear_cache() in reestablish_connection like so:

  public function reestablish_connection($close=true)
  {
    // if connection name property is null the connection manager will use the default connection
    $connection = $this->class->getStaticPropertyValue('connection',null);

    if ($close)
      ConnectionManager::drop_connection($connection);

    static::clear_cache();
    return ($this->conn = ConnectionManager::get_connection($connection));
  }
Igor Nikitin Sat Apr 07 06:14:09 -0400 2012

Hello,

There is another occasion - connection lost in Connection::query().

How do we access Model or Table instance to call reestablish_connection() here?

(1-4/4)