Title: Enterprise Ajax in PHP
1Enterprise Ajax in PHP
- Presented ByHedger Wang ??
2Front-end Engineer?????
Tech Lead of Yahoo! Groups
3? Things to ask About Enterprise AJAX?? AJAX
????????
4?JS??PHP Let JS call PHP
5???PHP??JavaSCriptNot PHP in JavaScript
-
-
- // here we are between the server and output,
known as client - hello ucwords('hello php world')
-
- // imagine that we would like to use a
variable - // defined somewhere in the server
- global something
-
-
http//webreflection.blogspot.com/2008/04/script-t
ype-php.html
6???Web ServiceAnd Not Web Service
UDDI
Service Broker
WSDL
WSDL
f(x)
SOAP
Service Requester
Service Provider
7?? ITS REFLECTION
8??JavaScript???PHP ???! Lets Call PHP Function
from JavaScript
str ?
function helloWorld() var onlLoad
function(str) //do something var
onError function(str) //do something
callPHPFunction(helloWorld, onlLoad, onError ,
Hedger)
9Reflection Diagram
JavaScriptfn( x )
JSON
PHP5class Handler
public fn( x )
JSON
10Example??
- Invalid Call????
- Parameters????
- Error Handling????
11JSON ?? / JSON ??JSON Response JSON Request
JSON Request
JSON Response
"id""ajax_request_1", "requests"
"action""whoAmI", "params" "Hedger
Wang", 30, "Chinese","Thai","Korean","Japa
nese", "email""hedgerwang_at_gmail.com",
"web site""http//www.hedgerwow.com"
"id""ajax_request_1","results""action""whoAm
I","data""My name is Hedger Wang and I am 30
years old. My fav foods are Chinese food, Thai
food, Korean food, Japanese food, . My
Contact info is email hedgerwang_at_gmail.com
web site http\/\/www.hedgerwow.com "
12??BATCHING
13Persistent http connections diagram
PHP Server
?????,????????????network.http.max-connections-pe
r-server 2
JavaScript Client
14Firebug These Request Compete the same
connection resources
JS
CSS
IMG
AJAX
15Example??
- Batching ??
- Dependency ??
- Binding??
16Pseudo Codes Snippets forDecoupled Logics
Binding Dependent Batching Request
function getContactName(i) var o1
actiongetPhoneNumber,params2 var o2
actioncallSomeone,dependent1,bind1
var o3 actionaskName,dependent1,bi
nd1 Request.post( or1,or2,or3) function
getContactNumber(i) var o1
actiongetPhoneNumber,params2
- index ) number this-numbersindex
-
- public callSomeOne(number) person
this-dial(number) return person
public askName(person) return
personname - ?
17Load Render Content
ServiceLogic
Data
Views Template
PHP Controller
JSON
HTML
DOM
HTML
JavaScript
18Example??
- HTML Include HTML???
- AJAX Include AJAX???
19?? QUEUE MANAGEMENT
20Queue Manager
- Many Developers
- Many Codes
- Many Languages
- Many Requests
- Many Datas
- And many to many
21We have requests from everywhere??????????
22???? ? ???? Defensive management or Optimistic
Anarchism
Server
Http Connections Management
Http Connections Queue Management
JavaScript Queue Management
Client
23??SYNCHRONIZED
24?????Baking A Duck
- Class Cook
- public function addFire()
- //wait to raise fire sleep(10)
systemsetFire(true) return true -
- public function bakeDuck()
- if(systemgetFire())return systembakeDuck
throw new Exception(no fire) -
- ?
-
- var Cook
- addFirefunction()
- //call PHP addFire
- bakeDuckfunction()
- //call PHP bakeDuck
-
-
-
- onclickCook.addFire()
- onclickCook.backDuck()
Add Fire
Bake Duck
25 ??????
Aynchronized Connection Model
????First In First Out
????Last In First Out
????One In One Out
26Example??
- ??Asynchronized
- ??Synchronized
27?REDUNDANCY
28?????Redundant Requests
getRSSFeedFromUrl( http//new.yahoo.com/rss/1
)
29??????? Remove Redundant Requests
30 Example??
- Without Redundancy Management
- With Redundancy Management
31??CACHE
32????????Server Side Request Cache Model
- Request URL ? Connect ? Expired ? Download
- Request URL ? Connect ? Not Expired ? Cache
Its Cached, maybe.
33???????Client Side Request Cache Model
- Request URL ? Expired ? Connect ? Download
- Request URL ? Not Expired ? Cache
Its Cache on Demand
oReq YAHOO.Groups.util.Ajax(sUrl,oCinfig)
oReq.setExpire(10) oReq.get()
34?????And more things.
35????Connection Validation
ader("Cache-Control no-store, no-cache")?riptAjax.setSignature(8799827E0-AOEIDJCXICXEHKX
I)
36????Prioritized Management
objRequest.setPriority(100)
37?????,???Lazy ConnectionDont Hurry, Be
Lazy.
objRequest.setThreshold(10)objRequest.setTimeout
(10,true)
38Enterprise Ajax in JAVA
39Enterprise Ajax in ASP.Net
40??Thanks
Hedger Wang ??Web http//www.hedgerwow.comMai
l hedgerwang_at_gmail.comYIM hedger14