How to manage PHP odbc_exec timeout?

柔情痞子 提交于 2019-12-12 03:46:01

问题


I've got a command-line PHP script that connects to SQL Server 2005 using an ODBC connection. It uses odbc_exec() to execute a stored procedure which may take a while to process, and I don't want it to timeout.

I've been unable to find anything in the PHP documentation regarding how to set the timeout for odbc_exec(). Does it default to an infinite wait?


回答1:


There's only so much you can do here. PHP's default script execution time is set to 30 seconds. There are numerous ways to change this, including the set_time_limit() function (found in the manual), and extending execution time by using ini_set, or using odbc_setoption

//extend execution time
$num_minutes = 5;
ini_set('max_execution_time', (60*$num_minutes)); //set timeout to 5 minutes

You can also change this setting inside your php.ini file. However, all of these only control the scope within what your apache server can control. If the database itself has a timeout, it will still cut off your call and return an error, even if your personally set execution times are elevated.




回答2:


According to php.net you can use odbc_setoption():

$result = odbc_prepare($conn, $sql);
odbc_setoption($result, 2, 0, 30);// 30 seconds timeout
odbc_execute($result);

So you can increase timeout to some bigger number depending on your need



来源:https://stackoverflow.com/questions/15278394/how-to-manage-php-odbc-exec-timeout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!