@Railchik

Как и где убрать timeout 30-40сек выполнения запроса php freetds mssql?

Собственно проблема такова. Есть сайт на debian(php mssql - freetds) и БД mssql на MS server 2008 R2. Все работает и работает замечательно. НО: если запрос тяжелый, то через ~ 40 сек скрипт падает. Запускаю через консоль php index.php

index.php
$link = mssql_connect('192.168.*****', 'user', 'pass');

if (!$link) {
    die('Something went wrong while connecting to MSSQL');
}
echo "Begin";

$time_start = microtime(true);

$res = mssql_query("select top 10 * from log where action like '%my_offer%' ");
//$res= mssql_query("select 1 ");

$time_end = microtime(true);

$time = $time_end - $time_start;
echo $time;
......



Begin
PHP Warning: mssql_query(): Query failed in /home/www/100g/report/index.php on line 18
40.11705493927

Через консоль tsql возвращает

root@test:/var/deploy/local/test2# tsql -S mssql -U web
locale is "en_US.UTF-8"
locale charset is "UTF-8"
Password:

1> select top 3 * from log where action like '%tender_offer%';
2> go
Msg 20004, Level 9, State -1, Server OpenClient, Line -1
Read from the server failed


Грешили на ms сервак.
Создали приложение на с++(компилили под виндой с подключение через ADODB::_ConnectionPtr ").
Через 30 сек выкидывает исключение
Время ожидания запроса истекло

Если указать таймаут у соединения как то так
ADODB::_ConnectionPtr m_conn = 0;
ADODB::_RecordsetPtr m_rs = 0;
HRESULT hr;
			try 
			{			
				hr = m_conn.CreateInstance(__uuidof(ADODB::Connection));
				<b>m_conn->CommandTimeout =200;</b>
				if FAILED(hr) {
					throw _com_error(hr);
				}
...........................

Возвращает результат.

Меняли все возможные настройки в php, freetds.

Тот же запрос в MSSQL Manager выполняется на ура.
Подскажите хотя бы куда копать, что попробывать где посмотреть.
Заранее спасибо.

UPD 1:
простой запрос select * from log висит не ограниченное количество времени. В мониторе активности MSSQL Server Manager studio

128 1 web ***** SUSPENDED SELECT PHP 5 117 ASYNC_NETWORK_IO External ExternalResource=ASYNC_NETWORK_IO 16 test RealTimeGroup

Если в php.ini прописать mssql.timeout меньше 40 сек, такой таймаут применяется, больше - нет.
# server specific section
[global]
        # TDS protocol version
        tds version = 8.0
        port = 1433

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
        dump file = /tmp/free1tds.log
        debug flags = 0xffff

        # Command and connection timeouts
        timeout = 300
        connect timeout = 300

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 6451200

# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[egServer70]
        host = ntmachine.domain.com
        port = 1433
        tds version = 7.0

[mssql]
        host = 192.168.*.*
        port = 1433
        tds version = 8.0
        client charset = UTF-8
        date format = %F %T
        dump file = /tmp/free2tds.log


Тут timeout вообще не применяется. Никак. Т.е. ставлю 10 или 20, все равно отрабатывает 40. Конфиг используется этот, т.к файл логов берется отсюда.

Наше решение:
Не знаю почему, но поменяв парамер KeepAlive tcp/ip в настройках sql сервера все заработало. Ставили для сервака и для клиента.
c7b0c2e55c7f467ba43b08266c02ba33.jpg

Так же возможно в реестре нужно вставить строчку KeepAliveTime HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters
  • Вопрос задан
  • 2638 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы