Ajax異步請求所耗時(shí)間比較
Jun 08, 2016 pm 05:33 PMAjax異步獲取目標(biāo)內(nèi)容所耗的時(shí)間對比.
方法1. MVC的模式訪問目錄對象的指定函數(shù),執(zhí)行查詢語句
方法2.直接創(chuàng)建sql語句和數(shù)據(jù)庫連接,執(zhí)行查詢語句 .
方法3.ZendFramework的Zend_Db執(zhí)行查詢語句
Html代碼:
將執(zhí)行以下Js代碼:
復(fù)制內(nèi)容到剪貼板
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) {}});
}
}
}
方法1.以MVC模式實(shí)現(xiàn)連接數(shù)據(jù)庫并執(zhí)行查詢語句的功能,?mod=admin&file=sys&method=checkusername所執(zhí)行的代碼如下:
復(fù)制內(nèi)容到剪貼板
$application = new SysAction;
$application->checkusername();
Class sysAction {
Function checkusername() {
$link = new DbLink();? ?? ?? ?? ?? ?? ?? ?? ?
$rs = $link->checkUser(“username=’crane’”);
}
}
共創(chuàng)建兩個(gè)對象.SysAction,DbLink,所耗時(shí)間如下:
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)
方法2.直接連接數(shù)據(jù)庫,并執(zhí)行查詢語句. test.php所執(zhí)行代碼如下:
復(fù)制內(nèi)容到剪貼板
$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)) {}
所耗時(shí)間如下:
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)
方法3.ZendFramework框架中Zend_Db類,執(zhí)行查詢語句,../private/zend/index.php代碼如下.
主文件部分代碼.
復(fù)制內(nèi)容到剪貼板
$frontController =Zend_Controller_Front::getInstance();
$frontController->throwExceptions(true);
$frontController->setControllerDirectory('application/controllers');
$frontController->dispatch();
控制器部分代碼:
復(fù)制內(nèi)容到剪貼板
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);
}
}
所耗時(shí)間如下:
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)
測試環(huán)境:
Windows NT 5.1 build 2600
Apache 2.0
PHP 5.2.5
Mysql 5.0.45
Zend Optimizer v3.3.0
PHP的面向?qū)ο笠恢币詠砭陀袪幾h,這里僅是在異步調(diào)用時(shí)所耗的時(shí)間對比。Mysql與php性能最優(yōu)的環(huán)境當(dāng)然是lamp,
有興趣的可以試試在最簡最優(yōu)環(huán)境下測試一下。PHP使用對象比不使用對象更耗時(shí)間是肯定的,
但PHP的cache和靜態(tài)化對項(xiàng)目的速度提高有決定性的意義,大型項(xiàng)目的開發(fā),這種機(jī)制是必不可少的。這里所做的測試,僅僅說明不同需求的項(xiàng)目,可采用不同的實(shí)現(xiàn)方法,沒必要凡用必OO
^_^……

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











??? ??? "??? ???? PIN ??? ?????"?? ???? ?????. ?? ?? ??? ??? ? ?? ?? ?? ?? ??? ???? ????? PIN ?? ??? ??? ?? ?????. ??? ?? ??? ???? Windows? ???? ?? ?????? ?? ???? ???? ????. ?? ?? ?? ????. ??? ??? ???? ???? ?? ??? ???? ?????. ???? Windows 11?? PIN? ????? ???? ??? ?????? ??? ??? ??? ???? ?? ? ???? ?? ???? ?? ?? ?? ?????. ??? ????? ???? ??? ? ? ????! ?? ?? ??? ?? ?? ???? ??? ????? ?? ?? ??? ??? ? ????. ?? ??

Windows 11? ???? ??? ???? ??? ??????. ???? ?????? ?? ? ???? ?? ??? ?? ??? ????? ??? ? ????. ? ?????? Windows ?? ???? ??? ???? ???? ??? ??? ? ??? ?? ??? ??? ?????. ? ??? ??? ???? ??? ?????? +? ?? ?? ?? ???. Windows?? ???? ???? ?? ??? ?????. ?? ?? ? ??? ?? ? 11" Width="643" Height="500" > ?? ??? ? ? ???? ?? ?? ?? ??? ?? ?? ?? ???? ?????. ?? ?? ? ?? ???? ?? ??? ????? ?? ??? ?? ???? ?? ??? ????? ?? ??? ?? ???? ?? ??? ???.

????? Windows 11? ?? ??? ??? ??? ???/?? ??? ?? ????. ??? ??? ???? ??? ? ????. ? ?????? ?? ???? ???? ??? ????? ????? ????? ??? ? ?? ??? ?? ??? ??? ?????. ?? ?? ??? ?? ?? ??? ??? ??? ? ????? ?, ?? ?? ???? ?? ?? ?? ??? ??? ????? ????? ???? ???? ??? ?? ?? ??? ??? ??? ? ????. ??? ??? ????? ?? ???? ?????. Windows 11?? ?? ??? ??? ???? ??? ?????? 1. ?? ?? ???? +? ?? ?? ?? ???. Windows"?? ??"?? ??? ??

?? ??? ???? ???? ?? ??? ??? ???? ??? ???? ? ?? ????. ? ?? ?? ??? ?? ???? ????? ???? ??? ??? ?? ? ? ??? ?? ????. ? ?? ??? ? ?? ??? ???? ????? ????. ??? ??? ???? ?? ? ?? ??? ?? ??? ?????? ??? ????????. ??? ???? ??? ?? ??? ? ?? ?? ??? ??? ?? ???? ? ????. Windows 11?? ?? ??? ??? ?? ??? ????? ??? ?????? 1. ?? ?? ???? ?? ??? ??? ?????. Windows??? ???? ???? ??? ?????. ?? ??? ??? ?????. ?? ??? ???? ?? ???? ??? ?????. "?? ??"? ?????.

Windows 11? ????? ?? ??? ???? ?? ??? ?? ?? ???? ??? ????. ? ???? ???? ??? ??, ?? ???? ???? ??? ????. ??? ??? ?? ??? ????? ??? ??? ?????. ??? ?? ?? ???? ???? ??? ?? ??? ?? ? ???? ???? ? ???? ??? ??? ??? ????? ?? ??? ???? ??? ??? ???. Custom Zoom? ??: ??? ???? ?? ??? ????? ??? ?????. ? ?? ???? ? ?? ?? ? ? ??? ?????. ?? ??? ? ?? ?????? ???? ??? ?? ?? ???? ??? ? ????. ??? ????? ??? ????? ? ??? ? ? ????. ?? ?? ??? ??? ? ????? ??? ? ????. ??? 11? ???? ??

?? ??? ?? ??? ??? ??? ? ???? ????, ?? ??? ??? ? ? ?? ?????. ?? ??? ???, ???? ???, ???? ?? ????? ?? ? ??? ???. ??? ??? ?? ?? ??? ??? ? ???, ?? ??? UI ??? ??? Windows 11??? ?? ?????. ??? ???? ? ??? ?? ?? Windows 11?? ??? ???? ?? ??? ??? ????. Windows 11?? ??? ???? ?? [10?? ??] ?? ??? ???? ?? ??? ???? Windows 11?? ??? ??? ? ????. ???? ?? ???? ???? ???? ???? ???? ?????. ????. ?? 1: ?? ?? ?? ?? ??? ???? ? ????.

HTTP ?? ?? 520? ??? ??? ???? ?? ? ? ?? ??? ???? ? ???? ??? ??? ? ??? ?????. ??? ??? ???? ?? ? ? ?? ??? ????? ???? ? ?????. ?? ?? ?? ??, ???? ?? ?? ?? ? ? ?? ??? ?? ??? ? ????. ?? ????? ?? ?? ??, ???? ??, ?? ??? ?? ?? ??? ?? ?????. ?? ?? 520 ??? ???? ???? ???? ?? ???? ???? ??? ??? ??? ?? ?? ?? ????.

???: 1. ??? ?? ??? ???? ??? ???? ?? ?? ??? ??????. 2. ????? ?? ?????? ????? ????? ?? localhost? ?? ???? ????. 3. ??? ??? ??????. 4. ???? ???? ?? ????? ???? ??? ???? ????. 5. ?? ???? ???? ??? ????? ??? ??? ???? ?? ????? ?????. ??? ?? ?? ?? IP ??? ??? ??? ???? ?????.
