<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Qi Yang</title>
	<atom:link href="http://yangqi.us/feed/" rel="self" type="application/rss+xml" />
	<link>http://yangqi.us</link>
	<description>Massachusetts, USA</description>
	<lastBuildDate>Thu, 22 Sep 2011 18:32:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Nginx+PHP(FPM)+MySQL+Memcache+eAccelerator on Debian6</title>
		<link>http://yangqi.us/lemp-on-debian-6-squezze/</link>
		<comments>http://yangqi.us/lemp-on-debian-6-squezze/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:31:38 +0000</pubDate>
		<dc:creator>yangqi</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://yangqi.us/?p=68</guid>
		<description><![CDATA[I recently rebuild my linux image on Linode, so I have to reinstall the LEMP stack again from ground. Last time was probably more than a year ago, with the help of many tutorials from google. So this time I decide to write what I did step by step for my reference in the future. I am using Debian 6 32bit with linux kernel 3.0.4. After first log in to your debian, first you want to add Dotdeb repository to &#8230; <br /><a href="http://yangqi.us/lemp-on-debian-6-squezze/">Read More <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently rebuild my linux image on Linode, so I have to reinstall the LEMP stack again from ground. Last time was probably more than a year ago, with the help of many tutorials from google. So this time I decide to write what I did step by step for my reference in the future. </p>
<p>I am using Debian 6 32bit with linux kernel 3.0.4. After first log in to your debian, first you want to add Dotdeb repository to the system repository list. Dotdeb is a repository containing packages of stable and latest LAMP or LEMP servers and their many useful extensions. To add that</p>
<pre>vi /etc/apt/sources.list</pre>
<p>Add following two lines to the bottom of the file</p>
<pre>deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all</pre>
<p>And then fetch the appropriate GnuPG key</p>
<pre>wget http://www.dotdeb.org/dotdeb.gpg
cat dotdeb.gpg | apt-key add -</pre>
<p>After that run </p>
<pre>apt-get update
apt-get upgrade</pre>
<p>Now we are ready to install the LEMP stack packages.</p>
<p><strong>1. Nginx</strong><br />
Since the dotdeb repository we just added already have the latest stable version of nginx 1.0.6, we don&#8217;t have to compile it from the official source, just run</p>
<pre>aptitude install nginx</pre>
<p>That&#8217;s it. The default location for the conf files is <code>/etc/nginx/</code> and there will be a init.d script <code>/etc/init.d/nginx</code> to start and stop nginx.<br />
We would want nginx start each time the system boots, run the command</p>
<pre>update-rc.d nginx defaults</pre>
<p><strong>2. PHP with FPM</strong><br />
PHP-FPM (PHP FastCGI Process Management) is a patch for PHP to improve PHP’s FastCGI capabilities and administration. It has been bundled with PHP since the PHP 5.3.3 so we don&#8217;t need to install it besides the PHP5</p>
<pre>aptitude -y install php5-cli php5-common php5-suhosin php5-fpm</pre>
<p>This only php5 with fpm, I need to add some more php extensions</p>
<pre>aptitude -y install php5-mysql php5-gd php5-curl php5-pear php5-mcrypt php5-memcache</pre>
<p>Next to start nginx and php5-fpm if they are not already started.</p>
<pre>/etc/init.d/nginx start
/etc/init.d/php5-fpm start</pre>
<p>Following is to configure nginx to redirect all php request to php-fpm to process</p>
<pre>vi /etc/nginx/sites-available/default</pre>
<p>The default www directory of nginx is /etc/share/nginx/www, if you still want it there, no need to change anything. I changed the directory to /var/www so I have to create them.</p>
<pre>mkdir /var/www
mkdir default
chown -R www-data:www-data /var/www
chown -R www-data:www-data /var/www/*</pre>
<p>My version looks like below</p>
<p>Note: I use this conf file only for the ip access to the site, not combined with any domain. I will create other conf file for each site later.</p>
<pre>server {
	listen   80; ## listen for ipv4; this line is default and implied
	#listen   [::]:80 default ipv6only=on; ## listen for ipv6

	root /var/www/default; # this is the web root directory of this site
	index index.html index.htm index.php;

	# Make site accessible from http://localhost/
	server_name 72.14.185.108; # if you wanna use a domain to access,
     # add domains after separated by space like yangqi.org *.yangqi.org

	#location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to index.html
	#	try_files $uri $uri/ /index.html;
	#}

	location /doc {
		root /usr/share;
		autoindex on;
		allow 127.0.0.1;
		deny all;
	}

	location /images {
		root /usr/share;
		autoindex off;
	}

	#error_page 404 /404.html;

	# redirect server error pages to the static page /50x.html
	#
	error_page 500 502 503 504 /50x.html;
	location = /50x.html {
		root /usr/share/nginx/www;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	# I used unix socket to pass the request which is in the memory and faster
	location ~ \.php$ {
		fastcgi_pass /dev/shm/nginx.socket;
        include fastcgi_params;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	location ~ /\.ht {
		deny all;
	}
}</pre>
<p>Now if you create  a simple php file index.php in directory /var/www/default </p>
<pre>&lt;?php echo phpinfo();?&gt;</pre>
<p>When you visit the ip address of your server you should be able to see the phpinfo page.</p>
<p><strong>3.MySQL</strong><br />
This one is easy, just run</p>
<pre>aptitude -y install mysql-server mysql-client</pre>
<p><strong>4.Memcache</strong></p>
<pre>aptitude -y install memcached php5-memcache</pre>
<p>For the configuration of those applications, I will create new posts for each one with detailed information.</p>
<p><strong>5.eAccelerator</strong><br />
For this one, we are gonna have to install it from the official source file. The current latest version is 0.9.6.1. Before compiling, you have to install php5-dev</p>
<pre>aptitude -y install php5-dev build-essential</pre>
<p>We are downloading from Sourceforge, the link is<br />
<a href="http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2/download">http://sourceforge.net/projects/eaccelerator/files/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2/download</a></p>
<p>Run following commands:</p>
<pre>wget -O eaccelerator-0.9.6.1.tar.bz2 http://downloads.sourceforge.net/project/eaccelerator/eaccelerator/eAccelerator%200.9.6.1/eaccelerator-0.9.6.1.tar.bz2?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Feaccelerator%2Ffiles%2Feaccelerator%2FeAccelerator%25200.9.6.1%2F&amp;ts=1316714345&amp;use_mirror=surfnet
tar -xvf eaccelerator-0.9.6.1.tar.bz2
cd eaccelerator-0.9.6.1
phpize
./configure
make &amp; make install</pre>
<p>If every command goes through without errors, the eaccelerator module should be installed, but it&#8217;s not in use yet. We have to configure php.ini to include the module.<br />
Usually there are multiple php.ini files, to see which file is in use right now you can see the phpinfo page just created or in the command line:</p>
<pre>/usr/sbin/php5-fpm -i | less</pre>
<p>If you follow the steps above, it should in <code>/etc/php5/fpm/php.ini</code>, add following code to the end of php.ini</p>
<pre>[eaccelerator]
extension="eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
eaccelerator.allowed_admin_path="/var/www/default/control.php"</pre>
<p>Then restart php-fpm</p>
<pre>/etc/init.d/php5-fpm restart</pre>
<p>Now go to you phpinfo page, if it looks like below, then you have the eaccelerator module in work.<br />
<a href="http://yangqi.us/wp-content/uploads/2011/09/eaccelerator.png"><img src="http://yangqi.us/wp-content/uploads/2011/09/eaccelerator.png" alt="" title="eaccelerator" width="411" height="66" class="aligncenter size-full wp-image-95" /></a></p>
<p>If you want to view the status of the eaccelerator and control it through web,</p>
<pre>cp control.php /var/www/default</pre>
<p>The default username is <em>admin</em>, password is <em>eAccelerator</em>. Please change the password in the control.php file!</p>
<p>Till here you have accomplished the basic set up of a LEMP server on Debian 6. However there are still configuration and optimization steps to go. These steps will be different for different machines, systems and environment. </p>
]]></content:encoded>
			<wfw:commentRss>http://yangqi.us/lemp-on-debian-6-squezze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>QR Code Generate Class in PHP</title>
		<link>http://yangqi.us/qr-code-generate-class-in-php/</link>
		<comments>http://yangqi.us/qr-code-generate-class-in-php/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 03:20:06 +0000</pubDate>
		<dc:creator>yangqi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[qrcode]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://yangqi.us/?p=5</guid>
		<description><![CDATA[A QR code (short for Quick Response) is a specific matrix barcode (or two-dimensional code), readable by dedicated QR barcode readers and camera phones. The code consists of black modules arranged in a square pattern on a white background. The information encoded can be text, URL or other data. QR code is pretty efficient in spreading messages to smartphone devices. You can use your iphone, ipad, android phone or other smartphones to scan the code anywhere, then you would be &#8230; <br /><a href="http://yangqi.us/qr-code-generate-class-in-php/">Read More <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>A QR code (short for Quick Response) is a specific matrix barcode (or two-dimensional code), readable by dedicated QR barcode readers and camera phones. The code consists of black modules arranged in a square pattern on a white background. The information encoded can be text, URL or other data.</p></blockquote>
<p>QR code is pretty efficient in spreading messages to smartphone devices. You can use your iphone, ipad, android phone or other smartphones to scan the code anywhere, then you would be able to add contacts, calendar event, open an url, send an email or any other information stored in the code, without typing.</p>
<p>It’s very simple to generate a QR code using Google Chart API. I encapsulate it in a php class for easy use. The code is as follows:</p>
<pre>&lt;?php
/**
 * This class generate QRCode using the API provided by google.
 * Feel free to use or modify code, but please keep reference.
 * @author Qi Yang &lt;yangqi86@gmail.com&gt;
 * @version 1.0 (04/15/2011)
 * @link http://yangqi.us
 *
 */
class QRCode {

	/**
	 * Image size
	 * @var string
	 */
	private $_imageSize = '150x150';
	/**
	 * Output encoding
	 * @var string
	 */
	private $_outputEncoding = 'UTF-8';
	/**
	 * Error correction level
	 * @var string
	 */
	private $_errorCorrectionLevel = 'L';
	/**
	 * Image margin
	 * @var string
	 */
	private $_margin = '0';
	/**
	 * Google qrcode api url
	 * @var string
	 */
	private $_apiUrl = 'http://chart.googleapis.com/chart';
	/**
	 * The data to encode
	 * @var string
	 */
	private $_data = '';

	/**
	 * Constructor calls config functions {@link
	 */
	function __construct($config = array()) {
		$this-&gt;setImageSize($config['imageSize']);
		$this-&gt;setOutputEncoding($config['outputEncoding']);
		$this-&gt;setErrorCorrectionLevel($config['errorCorrectionLevel']);
		$this-&gt;setMargin($config['margin']);
	}

	/**
	 * Set image size of the qrcode
	 *
	 * @param $imageSize
	 * @return NULL
	 */
	public function setImageSize($imageSize) {
		isset($imageSize) ? $this-&gt;_imageSize = $imageSize : NULL;
	}
	/**
	 * Set output encoding of the qrcode
	 *
	 * @param $outputEncoding
	 * @return NULL
	 */
	public function setOutputEncoding($outputEncoding) {
		isset($outputEncoding) ? $this-&gt;_outputEncoding = $outputEncoding : NULL;
	}
	/**
	 * Set error correction level of the qrcode
	 *
	 * @param $errorCorrectionLevel
	 * @return NULL
	 */
	public function setErrorCorrectionLevel($errorCorrectionLevel) {
		isset($errorCorrectionLevel) ? $this-&gt;_errorCorrectionLevel = $errorCorrectionLevel : NULL;
	}
	/**
	 * Set image margin of the qrcode
	 *
	 * @param $margin
	 * @return NULL
	 */
	public function setMargin($margin) {
		isset($margin) ? $this-&gt;_margin = $margin : NULL;
	}
	/**
	 * Set data to be encoded in the qrcode
	 *
	 * @param $data
	 * @return NULL
	 */
	public function setData($data) {
		isset($data) ? $this-&gt;_data = urlencode($data) : NULL;
	}

	/**
	 * Get encoded qrcode image link string
	 *
	 * @return string
	 */
	public function getLink() {
		return $this-&gt;_apiUrl . '?cht=qr&amp;chs=' . $this-&gt;_imageSize
			. '&amp;chl=' . $this-&gt;_data
			. '&amp;choe=' . $this-&gt;_outputEncoding
			. '&amp;chld=' . $this-&gt;_errorCorrectionLevel . '|' . $this-&gt;_margin;
	}

	/**
	 * Get encoded qrcode image by string
	 *
	 * @return string
	 */
	public function getImage() {
		$data = 'cht=qr&amp;chs=' . $this-&gt;_imageSize
			. '&amp;chl=' . $this-&gt;_data
			. '&amp;choe=' . $this-&gt;_outputEncoding
			. '&amp;chld=' . $this-&gt;_errorCorrectionLevel . '|' . $this-&gt;_margin;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $this-&gt;_apiUrl);
		curl_setopt($ch, CURLOPT_POST, TRUE);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
		curl_setopt($ch, CURLOPT_TIMEOUT, 30);
		curl_setopt($ch, CURLOPT_FAILONERROR, FALSE);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($ch, CURLOPT_HEADER, FALSE);
		$response = curl_exec($ch);
		if(  curl_errno($ch) ) {
			echo curl_error($ch);
		}
		curl_close($ch);

		return $response;
	}

	/**
	 * Output qrcode image to the browser
	 */
	public function render() {
		header('Content-type: image/png');
		echo $this-&gt;getImage();
	}

}

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://yangqi.us/qr-code-generate-class-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple snippet to get file extension in php</title>
		<link>http://yangqi.us/simple-snippet-to-get-file-extension-in-php/</link>
		<comments>http://yangqi.us/simple-snippet-to-get-file-extension-in-php/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 22:13:19 +0000</pubDate>
		<dc:creator>yangqi</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://yangqi.us/?p=13</guid>
		<description><![CDATA[Following is a simple snippet I use to get a file extension in php, notice that the strrpos function returns the last position of the string “.” in filename in case there are multiple dots in file name. &#60;?php /** * Function that returns file extension by its name. * @param unknown_type $fileName * @return $ext */ function fileExt($fileName) { /* sttrpos to get last position of "." */ $dot = strrpos($fileName, '.'); if($dot === FALSE) return FALSE; $ext = &#8230; <br /><a href="http://yangqi.us/simple-snippet-to-get-file-extension-in-php/">Read More <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Following is a simple snippet I use to get a file extension in php, notice that the strrpos function returns the last position of the string “.” in filename in case there are multiple dots in file name.</p>
<pre>&lt;?php
/**
 *  Function that returns file extension by its name.
 *  @param unknown_type $fileName
 *  @return $ext
 */
    function fileExt($fileName)
    {
        /* sttrpos to get last position of "." */
        $dot = strrpos($fileName, '.');
        if($dot === FALSE)
            return FALSE;

        $ext = substr($fileName, $dot+1);
        return $ext;
    }

    $fileName = "yangqi.us.txt";
    echo fileExt($fileName);
?&gt;</pre>
<p>After doing some research, I found an easier way to utilize the php function “pathinfo()“. The function returns an array containing information about dirname, basename, extension and filename of a given path string or a filename. The sample code is as follow:</p>
<pre>&lt;?php
/**
 *  Function that returns file extension by its name.
 *  @param unknown_type $fileName
 *  @return $ext
 */
    function fileExt($fileName)
    {
        $ext = pathinfo($fileName, PATHINFO_EXTENSION);
        return $ext;
    }

    $fileName = "yangqi.us.txt";
    echo fileExt($fileName);
?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://yangqi.us/simple-snippet-to-get-file-extension-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://yangqi.us/hello-world/</link>
		<comments>http://yangqi.us/hello-world/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 04:55:14 +0000</pubDate>
		<dc:creator>yangqi</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://yangqi.us/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is my first post. Read or comment on it, then start surfing!]]></description>
			<content:encoded><![CDATA[<p>Welcome to WordPress. This is my first post. Read or comment on it, then start surfing!</p>
]]></content:encoded>
			<wfw:commentRss>http://yangqi.us/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

