??  PHP??MySQL????????????????????????????????????????????????????????????????????????????????????Apache?????????????MySQL????
???????????Apache??????е?PHP?????????MySQL???????????????????Apache???web????????????Keep-Alive??
????Keep-Alive
????Keep-Alive??????????????httpЭ???????????????????????Keep-Alive??http????????????????????????Чurl???????????????????socket??url?????web?????????????TCP???????????????ε???????????????????????????????????????socket TCP?????????web??????????httpЭ?飬??????????web????????http???????body?????????????????????????socket??????????http???????body????????????????????????????????????????????????????????TCP??????????????????????????????η?????????TCP??????????????TCP?????????????4????????????????http????3???????4???????????????????????????????????????????socket???????????????????socket TCP?????????http???????????Keep-Alive????????http/1.0????????????????????????Connection:Keep-alive???????????????????????http1.1??????????????Apache???????????Keep-Alive?????????(Apache????1.2+???????Keep-Alive)????httpd.conf?????KeepAive???????????????On??MaxKeepAliveRequests?????0(??????TCP????????????????????С??????????TCPδ?????????£?????????????′??????????μ?TCP???????????????0?????????)????????mysql_pconnect????????KeepAliveTimeout?????15(???15??)??
?????????????Apache????????£????д?ж?????
????1<?php
????2   echo "Apache?????:". getmypid();
????3?>
???????????????PHP?????(Apache)??????????????????????棬????????????п????????????????15??????????????棬?????????????仯????а???????????????????????????????1??2??3??...15??16?????????15?????????????棬?????????б仯???????????????μ?Apache??????????15??????μ????????????????Apache???????KeepAliveTimeout?????????15????????????????????????web??????????KeepAlive??????£??????????http????????Apache??????????socket?????????????????????????????????????????KeepAliveTimeout?????????????????????????????Apache????socket???????′???????????????Apache?????????????????????????????15???????????棬???????????????μ????????????????????????Apache?????
?????????????????????????????TCP?????????????http??????????http???????????Connection:keep-alive??Keep-alive:15???У?????????????????????????socket????????????????????????15??????????????????????http????????????????????????????
????PHP?????
?????????PHP??MySQL??????????????hold?????????????PHP??mysql_pconnect???????????????£???????????mysql_pconnect??????Apache??????????hash key????hash??????????????????????????????hash????????????á???Щ??????ο??????(??????PHP5.3.8???ext/mysql/PHP_mysql.c???690??PHP_mysql_do_connect????)
#1.????hash key
user=php_get_current_user();//??????PHP?????(Apache)?????????
//hashed_details??hash key
hashed_details_length = spprintf(&hashed_details?? 0?? "MySQL__%s_"?? user);
#2.???δ????????????????hash????????persistent_list??????????????
/* try to find if we already have this link in our persistent list */
if (zend_hash_find(&EG(persistent_list)?? hashed_details?? hashed_details_length+1?? (void **) &le)==FAILURE) {
/* we don't */
...
...
/* hash it up(????hash??) */
Z_TYPE(new_le) = le_plink;
new_le.ptr = mysql;
if (zend_hash_update(&EG(persistent_list)?? hashed_details?? hashed_details_length+1?? (void *) &new_le?? sizeof(zend_rsrc_list_entry)?? NULL)==FAILURE) {
...
...
}
}
else
{/* The link is in our list of persistent connections(????????hash????)*/
...
...
mysql = (PHP_mysql_conn *) le->ptr;//??????????sql???????
...
...
}