PHP and Ajax - very very slow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How do you people use PHP with Ajax?

I have been using this code, but there must be something wrong because 
it takes too long to get the answer from the server. I really need, 
somehow, to check if the IE version is 5.

The main point is: where there more than 500 people connected to the DB 
it becomes really slow.

Ajax code:
var agt = navigator.userAgent.toLowerCase();
var isIe = (agt.indexOf('msie') != -1);
var isIe5 = (agt.indexOf('msie 5') != -1);
var uniqueCounter = (new Date).getTime();   

function createXmlHttpReq(handler) {
    if (isIe) {
        var control = (isIe5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
        try {
            xmlhttp = new ActiveXObject(control);
            xmlhttp.onreadystatechange = handler;
        } catch (e) {}
    } else {
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onload = handler;
        xmlhttp.onerror = handler;
    }
    return xmlhttp;
}

function xmlHttpGET(xmlhttp, url) {
  xmlhttp.open('GET', url, true);
  xmlhttp.send(null);
}   

function xmlHttpPOST(xmlhttp, url, arg) {
  xmlhttp.open('POST', url, true);
  xmlhttp.setRequestHeader("Content-Type", 
"application/x-www-form-urlencoded");
  xmlhttp.setRequestHeader("Content-Length", arg.length);
  xmlhttp.setRequestHeader('Connection','close');
  xmlhttp.send(arg);     
}

function sendRequestGET(url) {
  xmlhttp = createXmlHttpReq(function() {});
  xmlHttpGET(xmlhttp, url);
}

function sendRequestPOST(url, arg) {
  xmlhttp = createXmlHttpReq(function() {});
  xmlHttpPOST(xmlhttp, url, arg);
}
========================================================================
My JavaScript in .php file (example):
...
function GetPerfilIndividual(id){
    var arg = 'SOMETHING=1&SOME_ID=4343";
    var xmlhttp = createXmlHttpReq(function() {
        if(xmlhttp.readyState == 4) {
            if(xmlhttp.status == 200) {
                document.getElementById("DIV_DEST").innerHTML = 
xmlhttp.responseText;
            } else {
                document.getElementById("DIV_DEST").innerHTML = "<font 
color='red'>"+xmlhttp.status+" - "+xmlhttp.statusText+"</font>";
            }
        }   
    });
      xmlHttpPOST(xmlhttp, 'my_php_file.php', arg);   
}
...

my_php_file.php
- Access the database
- make about 8 SELECTs
- create some TABLEs
- closes database
- return



PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux