Comparison of the time elapsed between Ajax asynchronous requests

Source: Internet
Author: User
Tags zend

The time comparison that Ajax takes to get the target content asynchronously.
Method 1. The pattern of MVC accesses the specified function of the directory object, executing the query statement
Method 2. Directly create SQL statements and database connections, execute query statements.
Method 3. Zendframework zend_db Execute the query statement


HTML code:
<input type= "text" name= "username" id= "username" onblur= ' cek.checkuser () '/>


The following JS code will be executed:
Copy Content to Clipboard

Var Cek = {
Checkuser:function (user) {
if (!$ (' Modify '). Value | | $ (' default_user '). Value!= $ (user). Value) {
var url = "? Mod=admin&file=sys&method=checkusername";
var url = ' test.php ';
var url = '.. /private/zend/index.php ';
var pars = ';
var myajax = new Ajax.request (url,{method: ' Get ', parameters:pars,oncomplete:function (contents) {}});
}
}
}
Method 1. To implement the ability to connect to a database and execute a query statement in the MVC pattern,? Mod=admin&file=sys&method=checkusername executes the following code:
Copy Content to Clipboard

$application = new Sysaction;
$application->checkusername ();
Class Sysaction {
Function Checkusername () {
$link = new Dblink ();
$rs = $link->checkuser ("Username= ' crane '");
}
}
A total of two objects were created. Sysaction,dblink, the time consumed is as follows:

Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (63MS)
Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (62ms)
Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (62ms)
Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (62ms)
Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (62ms)
Get Http://localhost/admin/?mod=admin&file=sys&method=checkusername (63MS)


Method 2. Directly connect to the database and execute the query statement. test.php executes the following code:
Copy Content to Clipboard

$db = mysql_connect (' localhost ', ' root ', ' 123456 ');
mysql_select_db (' Test ');
$sql = "SELECT * from table where username= ' crane '";
$result = mysql_query ($sql, $db);
while ($row = Mysql_fetch_array ($result)) {}
The time consumed is as follows:

Get http://localhost/admin/test.php (15ms)
Get http://localhost/admin/test.php (15ms)
Get http://localhost/admin/test.php (15ms)
Get http://localhost/admin/test.php (15ms)
Get http://localhost/admin/test.php (15ms)
Get http://localhost/admin/test.php (15ms)


Method 3. Zendframework the zend_db class in the framework, execute the query statement,.. The/private/zend/index.php code is as follows.
Main file part code.
Copy Content to Clipboard

$frontController =zend_controller_front::getinstance ();
$frontController->throwexceptions (TRUE);
$frontController->setcontrollerdirectory (' application/controllers ');
$frontController->dispatch ();
Controller Part code:
Copy Content to Clipboard

Require_once ' zend/db.php ';
Class Indexcontroller Extendszend_controller_action {
function init () {
}
Functionindexaction () {
$params = Array (
"Host" => ' localhost ',
"username" => ' root ',
"Password" => ' 123456 ',
' dbname ' => ' test '
);
$user = ' crane ';
$db = zend_db::factory (' Pdo_mysql ', $params);
$select = $db->select ();
$select->from (' table ', ' username ')
->where ($db->quoteinto (' username=? ', ' Crane '))
;
$sql = $select->__tostring ();
$result = $db->fetchall ($sql);
}
}
The time consumed is as follows:

Get http://localhost/private/zend/index.php (125MS)
Get http://localhost/private/zend/index.php (141ms)
Get http://localhost/private/zend/index.php (110ms)
Get http://localhost/private/zend/index.php (141ms)
Get http://localhost/private/zend/index.php (109MS)
Get http://localhost/private/zend/index.php (141ms)



Test environment:

Windows NT 5.1 Build 2600
Apache 2.0
PHP 5.2.5
Mysql 5.0.45
Zend Optimizer v3.3.0

PHP object-oriented has always been controversial, and here is only the time spent in the asynchronous invocation of the comparison. MySQL and PHP the best performance environment is of course lamp,
Interested can try in the simplest optimal environment test. It is certain that PHP consumes more time than objects that don't use them.
But the cache and static of PHP have a decisive significance to the speed of the project, the development of large-scale projects, this mechanism is essential. Here the test, only to illustrate the different requirements of the project, can be implemented in different ways, no need to use the required Oo
^_^ ...
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.