0

I have 9 tables. I created a recoursive ajax function called nTables times (each for table) And into the ajax I call action.php with performed the search into every table.

The problem is that while performing the search, when I hit SHOW PROCESSLIST; in mysql, only have one Query running at time. And in my frontend page, the searches are performed one after another and not at the same time.

What can I do in order to mysql creates 9 connections at a time?

Here is my ajax:

function rAjax(thetables, i, thesearch){
    i++;
    $("#treethetables").hide();
    $("#divsearching").show("slow", function() {});
    var thetable=thetables[i];
    if(i<thetables.length){
        $.ajax({
            type: "POST",
            url: "app/action.php",
            data: ({
                txtBusca : thesearch,
                thetable: thetable,
            }),
            beforeSend: function(){
                $("#"+thetable).html("searching in "+thetable+"...");
            },
            success: function(data){
                totalOkTables--;
                console.warn(totalOkTables);
                if(totalOkTables==0){
                    $("#divsearching").hide();
                    $("#treethetables").show("slow", function() {});
                }
                $("#"+thetable).append(data)
            }
        });
        rAjax(thetables, i, thesearch)
    }
}

And here is my deffinition of the connection:

class vitDb{
    private $conn=NULL;
    private $db=NULL;
    private $selectdb=NULL;
    public $dbase;

    public function vitDb(){ 
        $hostname_conn = "127.0.0.1";
        $database_conn = "myBase";
        $username_conn = "root";
        $password_conn = "";
        $this->conn = mysql_connect($hostname_conn, $username_conn, $password_conn, true) or trigger_error(mysql_error(),E_USER_ERROR);
        $this->selectdb = mysql_select_db($database_conn, $this->conn);
        $this->db=$database_conn;
    }

    public function QSet($sql){//Regresa el Juego aunque esté vacío, y NULL si error.
        if($theSet=mysql_query($sql, $this->conn)){
            return $theSet;
        }else{
            return NULL;
        }
    }
}

And the call:

$my = new vitDb();
$db=$my->dbase;
$sql="SELECT * FROM $tabla WHERE ...";
$res=$my->QSet($sql);
#Staff

Hope Can help me thanks.

Fluffeh
  • 33,228
  • 16
  • 67
  • 80
Nax
  • 31
  • 4
  • ^ If you have amendments to the question, they can be edited in - use the 'edit' link above. – halfer Jan 20 '15 at 20:49
  • 2
    **Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).** They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). **Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement)** instead, and **use [PDO](http://us1.php.net/pdo).** – Jay Blanchard Jan 20 '15 at 20:49
  • Thanks for the comments for now I need to resolve this oldy :| – Nax Jan 20 '15 at 21:01
  • What happens if you use a `for` loop instead to send your ajax requests? – Matt Jan 20 '15 at 21:06
  • How could I do that Matt? I need to issue async and soimultaneously calls to the connections.. loop will execute one after another. – Nax Jan 20 '15 at 21:24

1 Answers1

-1

The browser limits you to two simultaneous requests. Separately, are you using PHP sessions on the server side? If so the session files use locking so that would be preventing more than one request at a time per session.

Yermo Lamers
  • 1,911
  • 14
  • 25
  • Thats it Yermo it was the problem (Using $_SESSION vars). Thank you very much. Now I can see multiple queries in my show processlist command. – Nax Jan 20 '15 at 21:41
  • I can see only 6 connections even though i have 9... Think will be the navigator? – Nax Jan 20 '15 at 21:54
  • I write custom session handlers to get around this problem when I need session support. As for the connections, yes, I believe that's being limited by the browser. If you're using Chrome you can use Developer tools to see the outgoing connections. – Yermo Lamers Jan 21 '15 at 12:41