Hello,
I have some long-running scripts which may take 5 minutes to many hours to complete. Those scripts work like that:
- Perform a query using a Model (instantiate it with
$model = new Model()
and then->save()
it) - Launch the execution of an external long running script (which does nothing on the application and does not use any Model or database connection)
- Perform a query on that same Model (for example
$model->setParam( 1 )->save();
)
The Database server has a wait_timeout
for connection with a value of 600
seconds (10 minutes).
Before executing instruction 3 I perform this:
$this->db->connect( $config->Database->toArray() );
in order to restore the connection (ref. https://olddocs.phalcon.io/en/latest/api/Phalcon_Db_Adapter_Pdo.html#methods )
I even tried that:
$db = $model->getWriteConnection();
$db->connect( $config->Database->toArray() );
But I always get this error when executing connect()
:
Phalcon\Db\Adapter\Pdo::connect(): send of 5 bytes failed with errno=32 Broken pipe
I could raise the value of wait_timeout
(for example to 8 hours) but the point is that I can not arbitrarily set a value that can always be valid.
I want my wait_timeout
parameter to be "some value" not depending on long running scripts.
I just need to be able to reconnect the application to the database without returning that error.
How can I do?
Thank you