Http Articles :
http://www.w3.org/Protocols/rfc2616/rfc2616.html
http://www.ietf.org/rfc/rfc2617.txt
http://www.ietf.org/rfc/rfc1945.txt
http://www8.org/w8-papers/5c-protocols/key/key.html
RFC2616 Status Code Definitions
Status code in PHP :
http://www.php.net/manual/zh/function.header.php
http://krisjordan.com/php-class-for-http-response-status-codes
http://www.jonasjohn.de/snippets/php/headers.htm
RFC2616 in Chinese : rfc2616_zh
Hypertext Transfer Protocol and PHP
Flow Flash AD using JavaScript and SWFObject
This article shows how to create a flow flash ad by using javascript together with swfobject.
@see getScroll.js
@see http://code.google.com/p/swfobject/
[codesyntax lang=”html4strict”]
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<title>flash flow ad using swfobject</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="getScroll.js"></script>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<!--main content-->
<div style="height:2000px;">content</div>
<!--ad-->
<div id="ad-flow" style="top:5px; left:100px; position:absolute;">
<div id="ad-test"></div>
<a style="text-align:left; display:block; background:#eee; width:120px;" href="javascript:void(0)" onclick="javascript:closeAd();" hidefocus="true">关闭</a>
</div>
<!--the flow ad script -->
<script type="text/javascript" src="ad-flow.js"></script>
</body>
</html>
[/codesyntax]
The ad-flow.js goes here :
[codesyntax lang=”javascript”]
// to close the ad and stop interval heart beat
function closeAd(id)
{
document.getElementById('ad-flow').style.visibility = "hidden";
document.getElementById('ad-test').style.visibility = "hidden";
window.clearInterval(int);
}
// global value to log the last position
var lastY = 0;
// the heart beat function
function heartBeat()
{
// get current top position
var curY = getScroll().t;
// speed : the bigger the faster
var speed = 0.05;
percent = speed * (curY - lastY);
if (percent > 0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
// keep stay there!
document.getElementById("ad-flow").style.top = parseInt(document.getElementById("ad-flow").style.top)
+ percent + "px";
// log last position
lastY = lastY + percent;
}
// beat every 1 microsecond
window.setInterval("heartBeat()", 1);
// flash ad embed by swfobject
var flashvars = {};
var params = {
// important for getUrl() in flash
allowscriptaccess : "always"
};
var attributes = {};
swfobject.embedSWF(
"http://www.kimbs.cn/static/ad-test.swf",
"ad-test",
"120",
"270",
"9.0.0",
"expressInstall.swf",
flashvars,
params,
attributes
);
[/codesyntax]
JavaScript Get Scroll Information
The script goes here : getScroll.js
[codesyntax lang=”javascript”]
// get scroll information (cross-browser compatibility)
function getScroll()
{
// t for top, l for left, w for width, h for height
var t, l, w, h;
if (document.documentElement && document.documentElement.scrollTop) {
// IE6 standards compliant
t = document.documentElement.scrollTop;
l = document.documentElement.scrollLeft;
w = document.documentElement.scrollWidth;
h = document.documentElement.scrollHeight;
} else if (document.body) {
// DOM compliant
t = document.body.scrollTop;
l = document.body.scrollLeft;
w = document.body.scrollWidth;
h = document.body.scrollHeight;
} else if (typeof(window.pageYOffset) == 'number') {
// Netscape compliant
t = window.pageYOffset;
l = window.pageXOffset;
w = window.innerWidth;
h = window.innerHeight;
} else {
alert('Error!');
}
return {t: t, l: l, w: w, h: h};
}
[/codesyntax]
Introduction to MongoDB
1. Download and install
http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip
unzip mongodb-win32-i386-1.6.5.zip to D:\mongodb
2. Create folder where database located
[codesyntax lang=”bash”]
$ mkdir D:\mongodb\data $ mkdir D:\mongodb\data\db
[/codesyntax]
3. Start mongodb server
[codesyntax lang=”bash”]
$ cd D:\mongodb\bin $ mongod.exe --dbpath=D:\mongodb\data\db --rest
[/codesyntax]
4. Web tool : http://localhost:28017/
5. Client tool for mongodb
[codesyntax lang=”bash”]
$ mongo.exe
[/codesyntax]
6. Create collection called mytestdb and limit the size (in fact we must use client tool)
[codesyntax lang=”bash”]
> db.createCollection("mytestdb", {capped:true, size:100000})
> show collections
[/codesyntax]
7. Driver for windows
https://github.com/mongodb/mongo-php-driver/downloads
https://github.com/downloads/mongodb/mongo-php-driver/mongo-1.1.3.zip
unzip mongo-1.1.3.zip
put mongo-1.1.3\mongo-1.1.3-php5.3vc6ts\php_mongo.dll to D:\xampp\php\ext\php_mongo.dll
[codesyntax lang=”ini”]
# modify php.ini extension=php_mongo.dll
[/codesyntax]
1. Download and install
[codesyntax lang=”bash”]
$ curl http://downloads.mongodb.org/linux/mongodb-linux-i686-1.6.4.tgz > mongo.tgz $ tar xzf mongo.tgz
[/codesyntax]
2. Create folder where database located
[codesyntax lang=”bash”]
$ sudo mkdir -p /data/mongo/db/ $ sudo chown `id -u` /data/mongo/db/
[/codesyntax]
3. Help and Launch
[codesyntax lang=”bash”]
$ ./mongo/bin/mongod --help $ ./mongo/bin/mongod --dbpath=/data/mongo/db/
[/codesyntax]
4. Client tool for mongodb
[codesyntax lang=”bash”]
$ ./mongo/bin/mongo
[/codesyntax]
1. Mongo instance and database connection
[codesyntax lang=”php”]
// connect to database server
$mongo = new mongo("192.168.0.132:27017");
// select database to handle
$db = $mongo->selectDB("mytest");
// select collection (just like table in mysql)
$collection = $db->selectCollection("cartoons");
[/codesyntax]
2. Insert
[codesyntax lang=”php”]
$myinfo = array( 'name' => 'Kim', 'email' => 'xqpmjh@gmail.com', 'sessions' => 0, ); $safe_insert = true; // $person is passed by reference $collection->insert($person, $safe_insert); echo $myid = $myinfo['_id'];
[/codesyntax]
3. Query
[codesyntax lang=”php”]
// find the person by both email and sessions exists
$filter = array(
'email' => 'xqpmjh@gmail.com',
'sessions' => array('$exists' => true),
);
// order by sessions desc
$cursor = $collection->find($filter)->sort(
array('sessions' => -1)
);
// show total docs
echo $total = $cursor->count();
// skip the first one and limit 3 docs
$cursor->limit(3)->skip(1);
foreach ($cursor as $user) {
var_dump($user);
}
[/codesyntax]
4. Create index
[codesyntax lang=”php”]
$collection->ensureIndex(
array('email' => 1),
array('unique' => true, 'background' => true)
);
[/codesyntax]
5. Update
[codesyntax lang=”php”]
$filter = array('email' => 'xqpmjh@gmail.com');
$new_document = array(
// increase sessions by one
'$inc' => array('sessions' => 1),
// set new name
'$set' => array(
'name' => 'kimho',
),
// unset second address
'$unset' => array('address.1' => 1),
);
// for duplicated records
$options['multiple'] = false;
$collection->update(
$filter,
$new_document,
$options
);
[/codesyntax]
6. Store big file (like video)
[codesyntax lang=”php”]
$grid = $db->getGridFS();
$metadata = array(
"filename" => "foo.avi",
"comment" => "wooooooo!",
"permissions" => array(
"kim" => "write",
"everybody" => "read",
)
);
$grid = $db->getGridFS();
$grid->storeFile("/data/video/avatar.avi", $metadata);
[/codesyntax]
7. Remove
[codesyntax lang=”php”]
// remove document which sessions equ 8
$filter = array('sessions' => 8);
$single = true;
$collection->remove($filter, $single);
[/codesyntax]
http://us.php.net/manual/en/book.mongo.php
http://www.mongodb.org/display/DOCS/Home
http://www.phpclasses.org/blog/post/118-Developing-scalable-PHP-applications-using-MongoDB.html
Version Control with SVN
1. Create trunk from proj_src(source code) :
[codesyntax lang=”bash”]
$ mv /root/proj_src /home/projects/ $ cd /home/projects/ $ svn import proj_src svn://192.168.1.119/proj/trunk -m "create proj trunk"
[/codesyntax]
2. To checkout the project :
[codesyntax lang=”bash”]
$ svn co svn://192.168.1.119/proj
[/codesyntax]
3. Add tags and first release :
[codesyntax lang=”bash”]
$ cd /home/projects/proj/ $ svn mkdir tags $ svn cp trunk tags/release_0.1.0
[/codesyntax]
4. Generate working copies for developers, special offer or someone else :
[codesyntax lang=”bash”]
$ svn mkdir branches $ svn cp tags/release_0.1.0 branches/kim $ svn cp tags/release_0.1.0 branches/cat $ svn cp tags/release_0.1.0 branches/special-x
[/codesyntax]
5. When finished :
[codesyntax lang=”bash”]
$ svn ci -m "everything is ready"
[/codesyntax]
6. Delete ?
[codesyntax lang=”bash”]
$ svn delete svn://192.168.1.119/branches/special-x -m "delete branch"
[/codesyntax]
7. Merge revisions of branches into trunk
[codesyntax lang=”bash”]
$ svn merge -r 50:100 svn://192.168.1.119/vtigercrm/branches/kim ./trunk/ $ svn ci -m "merge 50-100 from branches/kim to trunk"
[/codesyntax]
8. Revert merge
[codesyntax lang=”bash”]
$ cd trunk/ $ svn log $ svn merge -r 101:50 . $ svn ci -m "revert merge 100-50 from trunk"
[/codesyntax]
