Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP timeout running MSSQL SP

Tags:

php

sql-server

I am trying to run a MSSQL stored procedure from PHP using PDO. I do this all the time but with this SP it's timing out. The SP is rather complex and takes about 4 minutes to run.

I am calling it like this:

$setDate = '2014-01-03';

$queryMain = $coreDB->prepare("exec sp_ard :runDate");
$queryMain->bindParam("runDate",$setDate);
$queryMain->execute();

$e = $queryMain->errorInfo();
$d = $queryMain->fetchAll(PDO::FETCH_ASSOC);

print_r($e);
print_r($d);

When I run the page it runs for a minute or so then produces this error:

Array ( [0] => 08S01 [1] => 258 [2] => [Microsoft][SQL Server Native Client 10.0]TCP Provider: Timeout error [258]. ) 

I know the SP works fine. I can run it straight from the MSSQL management console. It takes about 4 minutes to run from there but it works fine.

I am trying to figure out how I can run this from PHP.

Any help would be great.

Thanks!

like image 526
Sequenzia Avatar asked Jan 03 '14 15:01

Sequenzia


1 Answers

You should be able to configure the timeout using PDO.

PDO::setAttribute

public bool PDO::setAttribute ( int $attribute , mixed $value )

PDO::ATTR_TIMEOUT: Specifies the timeout duration in seconds. Not all drivers support this option, and it's meaning may differ from driver to driver. For example, sqlite will wait for up to this time value before giving up on obtaining an writable lock, but other drivers may interpret this as a connect or a read timeout interval.

like image 151
ta.speot.is Avatar answered Sep 21 '22 23:09

ta.speot.is