I have a site at hostgator, using their "Business account". It's cheap, and comes with a private SSL cert. HOWEVER, their MySQL settings are such that any db connection goes stale fairly quickly, and then the hostgator staff try to convince you to use a VPS or dedicated server at multiple times the expense.
I'm creating and deploying WebAPIs, which can have a 'conversation' which exceeds 60 seconds. When this occurs, the db connection handle is stale, causing any db operations after my timeout to fail.
I'm in the process of implementing the following solution, but am curious if anyone else has solved this issue (where they can not modify their my.ini or my.cnf to give MySQL more resources) in a similar or completely different manner.
last part of a hook_update:
$ret = db_query( "UPDATE {my_table} set field1 = '%s', field2 = %d ... WHERE vid - %d", $node->field1, $node->field2, ... $node->vid );
if (!$ret) {
// get private storage directory for this node:
$cexStorage = _cex_front_getCexStore();
$nodeFilesPath = DRUPALROOT.'/'.$cexStorage.'/'.$node->storeDir;
$fname = $nodeFilesPath.'/recover.node';
$readyToWrite = serialize( $node );
file_put_contents( $fname, $readyToWrite );
if (file_exists( $fname )) {
_dbgReport( 'seems to have worked!' );
}
}
Then this is called in my hook_form, right after I determine that node->nid is valid:
function _cex_front_recover_node( &$node ) {
if (!isset($node->storeDir)) {
_dbgReport( '**************************** _cex_front_recover_node: no storeDir!!!' );
return;
}
// get private storage directory for this node:
$cexStorage = _cex_front_getCexStore();
$nodeFilesPath = DRUPALROOT.'/'.$cexStorage.'/'.$node->storeDir;
$fname = $nodeFilesPath.'/recover.node';
if (file_exists( $fname )) {
$recovered = file_get_contents( $fname );
if ($recovered) {
// no longer needed:
unlink( $fname );
$recoveredNode = unserialize( $recovered );
// restore the key values I need to proceed with this node:
$node->stage = $recoveredNode->stage;
$node->rnid = $recoveredNode->rnid;
$node->iris = $recoveredNode->iris;
cex_front_update( $node );
}
else {
_dbgReport( '********* failed to read "'.$fname.'"' );
}
}
}
I'll be pairing the logic down to only store the key fields I need, but this works! Sure beats upgrading my server at 3x the expense. Anyone else doing something like this?