The size of my data is giant, and sometimes, regarding the query, odbc loops infintely and totally blocks navigation on the website, until I restart my MSSQL server.
Hence, I want to create a timeout for odbc_exec(), able to stop the process on the DBMS after some time.
I couldn't find many solutions, but right now, my code looks like this:
Code: Select all
function run_in_bg($cmd, $winStyle = 0, $waitOnReturn = false) {
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run($cmd, $winStyle, $waitOnReturn);
$WshShell->Release();
return $oExec;
}
function query_database($query, $criteria = null){
$connection = DB_api::get_connection();
$pid = odbc_prepare ($connection, $query);
$pid2 = run_in_bg('c:\wamp\bin\php\php.5.2.11\php.exe sleep_and_rollback.php?pid='.$pid);
$result = odbc_execute($res, null) or $this->logger->err('DB_API: ODBC failed executing query');
//if odbc_execute is correct, then we stop $pid2 before it rollbacks the execution.
run_in_bg("TASKKILL /PID ".$pid2);
//(...end of method to treat result set..)
}
Code: Select all
<?php
$pid = $_GET['pid'];
sleep(10);
odbc_rollback();
?>
But of course, it doesn't work. Obviously, if another solution could let me limit execution time directly at SQL Server level, it'd be valid.
Thanks a lot for any of your time and help.