Coder Social home page Coder Social logo

connection-pool's People

Contributors

fising avatar hhxsv5 avatar paveljanda avatar sy-records avatar yunwuxin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

connection-pool's Issues

如何在 swoole 的自定义进程里使用连接池

目前看例子里的 Usage in Swoole Server 中,是通过绑定事件

        $this->swoole->on('WorkerStart', $createPools);
        $this->swoole->on('WorkerStop', $closePools);
        $this->swoole->on('WorkerError', $closePools);

似乎自定义进程没有对应的事件。

通过 addProcess() 方法启动的自定义进程(常驻),如何使用连接池呢?

感谢

How can I connect to a redis Cluster

Hi !

Can somebody show me how to make a Connection Pool implementation that connects to PhpRedis Cluster ?
Let's say I have these Redis Cluster nodes:

192.168.10.11, 192.168.10.12 and 192.168.10.13.
192.168.10.11 is the master

I am using Swoole 5.0.1

Do I need to call \Swoole::enableCoroutine(); ?

Thanks !

Borrow function of Connectoin Pool class requires a fix

On Line number 119 of "ConnectionPool.php" that lives in path "connection-pool/src/"

You return a new connection without pushing it into empty channel as below:
return $this->createConnection();

How about pushing this the new connection into channel (Pool) first, and then pop the connection, like below;

               $connection = $this->createConnection();`
               $ret = $this->pool->push($connection, static::CHANNEL_TIMEOUT);
                if ($ret === false) {
                    $this->removeConnection($connection);
                }

.. instead of returning the connection right away ?

Recommended Code with its full context, as below:

        if ($this->pool->isEmpty()) {
            // Create more connections
            if ($this->connectionCount < $this->maxActive) {
                $connection = $this->createConnection();                `
// Lets push new connection to the channel as below, because channel is initialized and still have space as condition ($this->connectionCount < $this->maxActive) has evaluated to true
               $ret = $this->pool->push($connection, static::CHANNEL_TIMEOUT);               
                if ($ret === false) {
                    $this->removeConnection($connection);
                }
            }
        }
        
        $connection = $this->pool->pop($this->maxWaitTime);

如何在其他class 使用這個靜態的db pool 或是實現依賴注入的方式

你好
我目前有在使用slim4配上swoole 當作我的開發工具
近期想要implement db pool的部分
非常喜歡你寫的方式
想請問你 有沒有什麼方法將pool 的instance 靜態化
來去讓其他class 使用

因為原本slim4的db是屬於依賴注入的方式
但身為小白的我卻不知道該如何下手

Sample pool connection for Wordpress

Hi, we hosted a bunches of Wordpress site and I want to lessen the load of our DB server. Is it possible to use this package as standalone similar to https://smproxy.louislivi.com/#/en/. And is it possible to separate the pool for read and write? If possible, kindly give a sample how to do that.

I am newbie regarding pool connection so bear with me. Thank you in advance.

connectionCount is incremented even no connection is created

If some error/exceptions occurs in borrow() -> createConnection(), variable $connectionCount is incremented but no connection exist (can't be returned to pool), next borrow connection is trying to pop connection from channel but there is no connection ...

I would suggest same fix as in this forked lib, can create MR: eltaline@e5f8b2d

Q: Assume from code, there is no way init (or create connection) again when is closed ?!

[QUESTION] Handle re-connect to server?

Can this connection pool handle re-connecting

Ex:

- Connection to the mysql server established
- Commands can be sent correctly
- Network cable is unplugged/disconnected.
- Commands try to send, detect that the network disconnected, and tries to reconnect.
- Network cable is plugged back in/network goes up
- Pool eventually reconnects, and resumes operations correctly.

Call to undefined method stdClass::close()

[2019-05-27 22:06:12 *28.7] ERROR zm_deactivate_swoole (ERROR 503): Fatal error: Uncaught Error: Call to undefined method stdClass::close() in /app/vendor/open-smf/connection-pool/src/Connectors/PhpRedisConnector.php:32
Stack trace:
#0 /app/vendor/open-smf/connection-pool/src/ConnectionPool.php(206): Smf\ConnectionPool\Connectors\PhpRedisConnector->disconnect(Object(stdClass))
#1 {main}
thrown in /app/vendor/open-smf/connection-pool/src/Connectors/PhpRedisConnector.php on line 32.

php 8.2 Error

#0 [8192]ErrorException in ConnectionPool.php line 264
Creation of dynamic property think\cache\driver\Redis::$__lat is deprecated
}
}
});
}

protected function createConnection()
{
    $this->connectionCount++;
    $connection = $this->connector->connect($this->connectionConfig);
    $connection->{static::KEY_LAST_ACTIVE_TIME} = time();
    return $connection;
}

protected function removeConnection($connection)
{
    $this->connectionCount--;
    Coroutine::create(function () use ($connection) {
        try {
            $this->connector->disconnect($connection);

PHP 8.2弃用了动态声明的类属性

并发量上去,数据库连接池对象创建失败PDO

:[Uncaught RuntimeException: Failed to connect the requested database: [2002] SQLSTATE[HY000] [2002] Operation timed out in //Connectors/PDOConnector.php:12

swoole 版本 4.5.9

测试工具ab 并发6000
不是数据库和swoole版本问题,用easyswoole测试没问题

连接不能响应,

环境

php 8.0.1
swoole 4.5.9

经过调试,貌似是Smf\ConnectionPool\ConnectionPool->init()里面go函数的问题
更改成这样可以响应:

    public function init(): bool
    {
        if ($this->initialized) {
            return false;
        }
        $this->initialized = true;
        $this->pool = new Channel($this->maxActive);
        $this->balancerTimerId = $this->startBalanceTimer($this->idleCheckInterval);
        for ($i = 0; $i < $this->minActive; $i++) {
            $connection = $this->createConnection();
            $ret = $this->pool->push($connection, static::CHANNEL_TIMEOUT);
            if ($ret === false) {
                $this->removeConnection($connection);
            }
        }
        return true;
    }

在运行的过程中有时候会报如下错误

在运行的过程中有时候会报错
PHP Fatal error: Swoole\Coroutine\Redis::__construct(): constructor can only be called once in /xxxx/swoole_api/vendor/open-smf/connection-pool/src/Connectors/CoroutineRedisConnector.php on line 11

协程客户端推荐使用

swoole文档新版本中,Redis 客户端,MySQL 客户端,不推荐再继续使用,可以使用 PHP 原生的函数 + 一键协程化。
可以在原先协程客户端的方式,增加使用原生Redis,Mysql配置吗

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.