Coder Social home page Coder Social logo

Comments (7)

rumplin avatar rumplin commented on August 11, 2024

using
max_connections=1000

from pdo_class_wrapper.

noncent avatar noncent commented on August 11, 2024

Hi @MokraCota,

First of all, I just wanted to say a big thank you for taking so much interest in this class wrapper and to put the efforts in the right direction.

Well, that's true because the wrapper isn't updated for a long time, you can see it passes the decade almost and haven't bit get updated yet. But now if people start taking interest in it I will certainty update the class wrapper in the most advance and in very optimized way.

to answer your question regarding the Persistent connection Yes! The good news is here and you can pass the PDO native attributes which come inbuilt with PDO to get the benefits of the persistent connections.

// use persistent connection
public function __construct( $dsn = array() ) {
.....
parent::__construct( "mysql:host=$host; dbname=$dbname", $username, $password, array(
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
    **PDO::ATTR_PERSISTENT => true**
) );
.....

I have tested the Persistent connection without a single glitch (max connection is 151 MariaDB) -

for ($i = 0; $i<=1000; $i++) {
  $db = new PdoWrapper($dbConfig);
  $rs = $db->select('s3upload')->results();
  echo str_repeat("\t", 2) . 'CON NO: ' . $i;
  echo '<pre>', print_r($rs, 1), '</pre>';
}

Much appreciate your unconditional help and support and I wish good health to you.

--
Cheers!!

from pdo_class_wrapper.

rumplin avatar rumplin commented on August 11, 2024

I am using this wrapper like this

in my main php script I initialize
$db = new PdoWrapper($dbConfig);

then I have a few dozen
$db->pdoQuery, $db->select, $db->update, etc...

then I include this main php script into my worker script php
and there I again use $db as a global variable in my functions

require_once "include/main.php";

function worker($arr)
{
    global $db;
    foreach ($arr as $item) {
        $db->pdoQuery("UPDATE ...;");
    }
}

am I using this wrapper wrong? should I initiate it in each script?

from pdo_class_wrapper.

rumplin avatar rumplin commented on August 11, 2024

Just took a look at my class, it seems I have an old version because
PDO::ATTR_PERSISTENT => true

is missing in mine. I'll update the script now and test again.

from pdo_class_wrapper.

noncent avatar noncent commented on August 11, 2024

I can insert 10K+ rows in a loop without any issue. Using global vars isn't opens the new connection it's class initializing which invoke the class to create a new instance with new connections in absence of a persistence connection.

from pdo_class_wrapper.

rumplin avatar rumplin commented on August 11, 2024

How could I find out which script is causing these issues? I'm not an experienced PHP programmer.
I have many scripts that have traffic, but I can't figure out which one is causing issues.

from pdo_class_wrapper.

rumplin avatar rumplin commented on August 11, 2024

Issue resolved by increasing mysql max connections value
max_connections=2000

you can close this ticket

from pdo_class_wrapper.

Related Issues (17)

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.