# Req #51295: busyTimeout method for SQLite3

- Thread: https://externals.io/message/47253
- Original archive: https://news-web.php.net/php.internals/47253
- Started by Mark Karpeles on 2010-03-14T07:39:10+00:00
- Messages: 6
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #47253 — Mark Karpeles — 2010-03-14T07:39:10+00:00

URL: https://externals.io/message/47253#47253

Hello,

I've been encountering a problem with SELECT queries and SQLite3 as load
was growing on my system. From times to times I was getting this error:

Warning: SQLite3Stmt::execute(): Unable to execute statement: database
is locked

After searching on google I saw I should call sqlite3_busy_timeout() and
found out that there was no way to call it from the SQLite3 extension
(which is new to PHP 5.3.x).

Here's a patch that will add this method to the SQLite3 class:

http://bugs.php.net/51295
https://ookoo.org/svn/snip/php_5_3-sqlite3-busytimeout-method.patch

Any comment welcome.


Mark

---

## #47254 — Jess Portnoy — 2010-03-14T07:57:22+00:00

URL: https://externals.io/message/47253#47254 · In reply to: #47253

Hello Mark,

Note that while indeed sqlite3_busy_timeout() is not extended by the 
SQLite3 and PDO_SQLITE extensions, it is called internally in 
ext/pdo_sqlite/sqlite_driver.c.
I think it is a good idea to extend it but also, that if you do, it 
should probably also be done for PDO_SQLITE as it may be useful there as 
well.

May the source be with you,
Best regards,
Jess Portnoy



Mark Karpeles wrote:
> Hello,
>
> I've been encountering a problem with SELECT queries and SQLite3 as load
> was growing on my system. From times to times I was getting this error:
>
> Warning: SQLite3Stmt::execute(): Unable to execute statement: database
> is locked
>
> After searching on google I saw I should call sqlite3_busy_timeout() and
> found out that there was no way to call it from the SQLite3 extension
> (which is new to PHP 5.3.x).
>
> Here's a patch that will add this method to the SQLite3 class:
>
> http://bugs.php.net/51295
> https://ookoo.org/svn/snip/php_5_3-sqlite3-busytimeout-method.patch
>
> Any comment welcome.
>
>
> Mark

---

## #47255 — Mark Karpeles — 2010-03-14T08:14:41+00:00

URL: https://externals.io/message/47253#47255 · In reply to: #47254

Hi,

I checked around PDO (which I don't use at all, but the source is
usually a good documentation).

The timeout can be changed for SQLite and SQLite3 PDO drivers with:

$pdo->setAttribute(PDO::ATTR_TIMEOUT, <value_in_seconds>)

I see that PDO::ATTR_TIMEOUT is not documented on
http://php.net/manual/en/pdo.setattribute.php - it might be a good idea
to fix this :)


Mark

Le dimanche 14 mars 2010 à 09:57 +0200, Jess Portnoy a écrit :
> Hello Mark,
> 
> Note that while indeed sqlite3_busy_timeout() is not extended by the 
> SQLite3 and PDO_SQLITE extensions, it is called internally in 
> ext/pdo_sqlite/sqlite_driver.c.
> I think it is a good idea to extend it but also, that if you do, it 
> should probably also be done for PDO_SQLITE as it may be useful there as 
> well.
> 
> May the source be with you,
> Best regards,
> Jess Portnoy
> 
> 
> 
> Mark Karpeles wrote:
> > […]

---

## #47256 — Jess Portnoy — 2010-03-14T08:17:42+00:00

URL: https://externals.io/message/47253#47256 · In reply to: #47255

Hi Mark,

I agree but I'm not the maintainer for PDO_SQLITE, I just happen to know 
it somewhat and thought it can be useful to you as reference. I am CCing 
Wez Furlong who I believe is the lead for it.

May the source be with you,
Best regards,
Jess Portnoy



Mark Karpeles wrote:
> Hi,
>
> I checked around PDO (which I don't use at all, but the source is
> usually a good documentation).
>
> The timeout can be changed for SQLite and SQLite3 PDO drivers with:
>
> $pdo->setAttribute(PDO::ATTR_TIMEOUT, <value_in_seconds>)
>
> I see that PDO::ATTR_TIMEOUT is not documented on
> http://php.net/manual/en/pdo.setattribute.php - it might be a good idea
> to fix this :)
>
>
> Mark
>
> Le dimanche 14 mars 2010 à 09:57 +0200, Jess Portnoy a écrit :
>   
> > […]

---

## #47263 — Wez Furlong — 2010-03-14T13:15:37+00:00

URL: https://externals.io/message/47253#47263 · In reply to: #47256

I'm sure that the docs team will add this to the manual if you ask  
them politely.

Specifically, PDO_SQLITE defaults to a 60 second busy timeout.  This  
can be changed by setting PDO::ATTR_TIMEOUT.  The value is specified  
in seconds.

ISTR that this option can also be specified for some of the other  
database drivers to affect the network timeout when processing a query.

--Wez.



> Hi Mark,
>
> I agree but I'm not the maintainer for PDO_SQLITE, I just happen to  
> know it somewhat and thought it can be useful to you as reference. I  
> am CCing Wez Furlong who I believe is the lead for it.
>
> May the source be with you,
> Best regards,
> Jess Portnoy
>
>
>
> Mark Karpeles wrote:
> > […]

---

## #47344 — Joey Smith — 2010-03-16T21:48:42+00:00

URL: https://externals.io/message/47253#47344 · In reply to: #47263

> I'm sure that the docs team will add this to the manual if you ask them 
> politely.
>
> Specifically, PDO_SQLITE defaults to a 60 second busy timeout.  This can 
> be changed by setting PDO::ATTR_TIMEOUT.  The value is specified in 
> seconds.
>
> ISTR that this option can also be specified for some of the other  
> database drivers to affect the network timeout when processing a query.

A nod's as good as a wink. :) This has been committed.
