PHPackages                             wwaayyaa/mysql-timeout - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. wwaayyaa/mysql-timeout

ActiveLibrary[Database &amp; ORM](/categories/database)

wwaayyaa/mysql-timeout
======================

Customizing the timeout for a database query

1.0.2(9y ago)6281MITPHPPHP &gt;=5.3

Since Sep 27Pushed 9y ago1 watchersCompare

[ Source](https://github.com/wwaayyaa/mysql-timeout)[ Packagist](https://packagist.org/packages/wwaayyaa/mysql-timeout)[ RSS](/packages/wwaayyaa-mysql-timeout/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (4)DependenciesVersions (3)Used By (0)

mysql-timeout
=============

[](#mysql-timeout)

Customizing the timeout for a database query

Install
-------

[](#install)

composer.json

```
{
"require": {
    "wwaayyaa/mysql-timeout":  "dev-master"
  }
}
```

`$ composer install`

Example
-------

[](#example)

php code

```
    $conf = Conf::$db1;
    print_r($conf);

    $d = new MysqlTimeout($conf);

    echo "now:".time()."\n";
    $r = $d->query('select sleep(2) as `sleep`,2 as `sec`;');
    print_r($r);
    echo "sleep 2s,now:".time()."\n";
    try{
    $r = $d->query('select sleep(5) as `sleep`,5 as `sec`;',3);
    }catch(Exception $e){
        echo sprintf("error message:%s ,error code : %d \n",$e->getMessage(),$e->getCode());
    }
    echo "sleep 5s but timeout is 3s,so throw a error.now:".time()."\n";

    $d = new MysqlTimeout($conf);//must new a MysqlTimeout. because
    $r = $d->query('select sleep(5) as `sleep`,5 as `sec`;',6);
    print_r($r);
    echo "sleep 5s success,because timeout is 6s. now:".time()."\n";

    //Other methods
    $r = $d->update("update dtk_zhibo_chat_log set addtime=now() where id = 6 or id = 17;");
    echo sprintf("success rows:%d \n",$r);
    $r = $d->insert("insert into dtk_zhibo_chat_log (zhiboId,content) values (1292,'test');");
    echo sprintf("primary id:%d \n",$r);
```

result

```
Array
(
    [host] => 127.0.0.1
    [port] => 3306
    [user] => root
    [password] => root
    [dbname] => test
    [charset] => utf8
)
now:1475056910
Array
(
    [0] => Array
        (
            [sleep] => 0
            [sec] => 2
        )

)
sleep 2s,now:1475056912
error message:timeout ,error code : 922922
sleep 5s but timeout is 3s,so throw a error.now:1475056915
Array
(
    [0] => Array
        (
            [sleep] => 0
            [sec] => 5
        )

)
sleep 5s success,because timeout is 6s. now:1475056920
success rows:2
primary id:1036
```

Method
------

[](#method)

```
	/**
     * @return mixed  query data
     */
	public function query($sql, $timeout = 3);

	/**
     * @return int   rows count
     */
	public function update($sql, $timeout = 3);

	/**
     * @return int   data primary id
     */
	public function insert($sql, $timeout = 3);

	/**
     * @return int   rows count
     */
	public function delete($sql, $timeout = 3);
```

Args
----

[](#args)

### config

[](#config)

- host | must '127.0.0.1'
- port | non-must '3306'
- user | must 'root'
- password | must 'root'
- dbname | must 'text'
- charset | must 'utf8'
- timeout | non-must 3

### timeout (defalut : `3`)

[](#timeout-defalut--3)

- The MsyqlTimeout inspection cycle is `0.05` seconds,
- so the minimum value of the $timeout parameter is 0.05,
- the maximum value depends on the PHP.ini `max_execution_time` and MySQL `timeout settings`.

Exception
---------

[](#exception)

### errorcode

[](#errorcode)

> If the query timeout, MysqlTimeout will throw an exception, the exception number `922922`

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

3563d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6279538?v=4)[王杨](/maintainers/wwaayyaa)[@wwaayyaa](https://github.com/wwaayyaa)

---

Top Contributors

[![wwaayyaa](https://avatars.githubusercontent.com/u/6279538?v=4)](https://github.com/wwaayyaa "wwaayyaa (23 commits)")

---

Tags

mysqlquerytimeout

### Embed Badge

![Health badge](/badges/wwaayyaa-mysql-timeout/health.svg)

```
[![Health](https://phpackages.com/badges/wwaayyaa-mysql-timeout/health.svg)](https://phpackages.com/packages/wwaayyaa-mysql-timeout)
```

###  Alternatives

[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4563.1M37](/packages/aura-sqlquery)[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921530.0k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

922281.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

922249.3k8](/packages/fpdo-fluentpdo)[nilportugues/sql-query-builder

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation.

426242.6k6](/packages/nilportugues-sql-query-builder)[clancats/hydrahon

Fast &amp; standalone PHP MySQL Query Builder library.

280212.2k6](/packages/clancats-hydrahon)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
