<?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>Zirkan</title>
	<atom:link href="http://zirkan.com/feed" rel="self" type="application/rss+xml" />
	<link>http://zirkan.com</link>
	<description>Zirkan WEB Development and Design</description>
	<lastBuildDate>Fri, 11 Nov 2011 22:08:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Nginx: Caching Proxy</title>
		<link>http://zirkan.com/tips/nginx-caching-proxy.php</link>
		<comments>http://zirkan.com/tips/nginx-caching-proxy.php#comments</comments>
		<pubDate>Fri, 11 Nov 2011 22:08:10 +0000</pubDate>
		<dc:creator>zirkan</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://zirkan.com/?p=464</guid>
		<description><![CDATA[Recently I started to tackle a load problem on one of my personal sites, the issue was that of a poorly written but exceedingly MySQL heavy application and the load it would induce on the SQL server when 400-500 people were hammering the site at once. Further compounding this was Apache’s horrible ability to gracefully [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started to tackle a load problem on one of my personal sites, the issue was that of a poorly written but exceedingly MySQL heavy application and the load it would induce on the SQL server when 400-500 people were hammering the site at once. Further compounding this was Apache’s horrible ability to gracefully handle excessive requests on object heavy pages (i.e: images). This left me with a site that was almost unusable during peak hours — or worse — would crash the MySQL server and take Apache with it by frenzied F5ing from users.</p>
<p><span id="more-464"></span></p>
<p>I went through all the usual rituals in an effort to better the situation, from PHP APC then Eaccelerator, to mod_proxy+mod_cache, to tuning Apache timeouts/prefork settings and adjusting MySQL cache/buffer options. The extreme was setting up a MySQL replication cluster with MySQL-Proxy doing RW splitting/load balancing across the cluster and memcached, but this quickly turned into a beast to manage and memcached was eating memory at phenomenal rates.</p>
<p>Although I did improve things a bit, I had done so at the expense of vastly increased hardware demand and complexity. However, the site was still choking during peak hours and in a situation where switching applications and/or getting it reprogrammed is not at all an option, I had to start thinking outside the box or more to the point, outside Apache.</p>
<p>I have experience with lighttpd and pound reverse proxy, they are both phenomenal applications but neither directly handles caching in a graceful fashion (in pounds case not at all). This is when I took a look a nginx which to date I had never tried but heard many great things about. I fired up a new Xen guest running CentOS 5.4, 2GB RAM &amp; 2 CPU cores….. an hour later I had nginx installed, configured and proxy-caching traffic for the site in question.</p>
<p><strong>The impact was immediate and significant</strong> — the SQL server loads dropped from an average of 4-5 down to 0.5-1.0 and the web server loads were near non-existent from previously being on the brink of crashing every afternoon.</p>
<p><strong>Enough with my ramblings, lets get into nginx</strong>. You can download the latest release from <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://nginx.org/" >http://nginx.org</a></noindex> and although I could not find a binary version of it, compiling was straight forward with no real issues.</p>
<p>First up we need to satisfy some requirements for the configure options we will be using, I encourage you to look at ‘./configure –help’ list of available options as there are some nice features at your disposal.</p>
<pre>yum install -y zlib zlib-devel openssl-devel gd gd-devel pcre pcre-devel</pre>
<p>Once the above packages are installed we are good to go with downloading and compiling the latest version of nginx:</p>
<pre>wget http://nginx.org/download/nginx-0.8.36.tar.gz
tar xvfz nginx-0.8.36.tar.gz
cd nginx-0.8.36/
./configure --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_image_filter_module --with-http_gzip_static_module
make &amp;&amp; make install</pre>
<p>This will install nginx into ‘/usr/local/nginx’, if you would like to relocate it you can use ‘–prefix=/path’ on the configure options. The path layout for nginx is very straight forward, for the purpose of this post we are assuming the defaults:</p>
<pre>[root@atlas ~]# ls /usr/local/nginx
conf  fastcgi_temp  html  logs  sbin

[root@atlas nginx]# cd /usr/local/nginx

[root@atlas nginx]# ls conf/
fastcgi.conf  fastcgi.conf.default  fastcgi_params  fastcgi_params.default  koi-utf  koi-win  mime.types  mime.types.default  nginx.conf  nginx.conf.default  win-utf</pre>
<p>The layout will be very familiar to anyone that has worked with Apache and true to that, nginx breaks the configuration down into a global set of options and then the individual web site virtual host options. The ‘conf/’ folder might look a little intimidating but you only need to be concerned with the nginx.conf file which we are going to go ahead and overwrite, a copy of the defaults is already saved for you as nginx.conf.default.</p>
<p>My nginx configuration file is available at <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://www.rfxn.com/downloads/nginx.conf.atlas" >http://www.rfxn.com/downloads/nginx.conf.atlas</a></noindex>, be sure to rename it to nginx.conf or copy the contents listed below into ‘conf/nginx.conf’:</p>
<pre>user  nobody nobody;

worker_processes     4;
worker_rlimit_nofile 8192;

pid /var/run/nginx.pid;

events {
  worker_connections 2048;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status  $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/nginx_access.log  main;
    error_log  logs/nginx_error.log debug;

    server_names_hash_bucket_size 64;
    sendfile on;
    tcp_nopush     on;
    tcp_nodelay    off;
    keepalive_timeout  30;

    gzip  on;
    gzip_comp_level 9;
    gzip_proxied any;

    proxy_buffering on;
    proxy_cache_path /usr/local/nginx/proxy levels=1:2 keys_zone=one:15m inactive=7d max_size=1000m;
    proxy_buffer_size 4k;
    proxy_buffers 100 8k;
    proxy_connect_timeout      60;
    proxy_send_timeout         60;
    proxy_read_timeout         60;

    include /usr/local/nginx/vhosts/*.conf;
}</pre>
<p>Lets take a moment to review some of the more important options in nginx.conf before we move along…</p>
<p><strong>user nobody nobody;</strong><br />
If you are running this on a server with an apache install or other software using the user ‘nobody’, it might be wise to create a user specifically for nginx (i.e: <strong>useradd nginx -d /usr/local/nginx -s /bin/false</strong>)</p>
<p><strong>worker_processes 4;</strong><br />
This should reflect the number of CPU cores which you can find out by running ‘<strong>cat /proc/cpuinfo | grep processor</strong>‘ — I recommend a setting of at least 2 but no more than 6, nginx is VERY efficient.</p>
<p><strong>proxy_cache_path /usr/local/nginx/proxy … inactive=7d max_size=1000m; </strong><br />
The ‘inactive’ option is the maximum age of content in the cache path and the ‘max_size’ is the maximum on disk size of the cache path. If you are serving up lots of object heavy content such as images, you are going to want to increase this.</p>
<p><strong>proxy_send|read_timeout 60;</strong><br />
These timeout values are important, if you run any scripts through admin interfaces or other maintenance URL’s, these values will cause the proxy to time them out — that said increase them to sane values as appropriate, anything more than 300 is probably excessive and you should consider running such tasks from cronjobs.</p>
<p><strong>Apache style MaxClients</strong><br />
Finally, maximum amount of connections, or MaxClients, that nginx can accept is determined by <strong>worker_processes * worker_connections/2</strong> (2 fd per session) <strong>= 8192 MaxClients</strong> in our configuration.</p>
<p>Moving along we need to create two paths that we defined in our configuration, the first is the content caching folder and the second is where we will create our vhosts.</p>
<pre>mkdir /usr/local/nginx/proxy /usr/local/nginx/vhosts /usr/local/nginx/client_body_temp /usr/local/nginx/fastcgi_temp  /usr/local/nginx/proxy_temp

chown nobody.nobody /usr/local/nginx/proxy /usr/local/nginx/vhosts /usr/local/nginx/client_body_temp /usr/local/nginx/fastcgi_temp  /usr/local/nginx/proxy_temp</pre>
<p>Lets go ahead and get our initial vhosts file created, my template is available from<noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://www.rfxn.com/downloads/nginx.vhost.conf" >http://www.rfxn.com/downloads/nginx.vhost.conf</a></noindex> and should be saved to ‘/usr/local/nginx/vhosts/myforums.com.conf’, the contents of which are as follows:</p>
<pre>server {
    listen 80;
    server_name myforums.com alias www.myforuns.com;

    access_log  logs/myforums.com_access.log  main;
    error_log  logs/myforums.com_error.log debug;

    location / {
        proxy_pass http://10.10.6.230;
        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

        proxy_cache               one;
        proxy_cache_key         backend$request_uri;
        proxy_cache_valid       200 301 302 20m;
        proxy_cache_valid       404 1m;
        proxy_cache_valid       any 15m;
        proxy_cache_use_stale   error timeout invalid_header updating;
    }

    location /admin {
        proxy_pass http://10.10.6.230;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    }
}</pre>
<p>The obvious changes you want to make are ‘myforums.com’ to whatever domain you are serving, you can append multiple aliases to the server_name string such as ‘<strong>server_name domain.com alias www.domain.com alias sub.domain.com;</strong>‘. Now, lets take a look at some of the important options in the vhosts configuration:</p>
<p><strong>listen 80;</strong><br />
This is the port which nginx will listen on for this vhost, by default unless you specify an IP address with it, you will bind port 80 on all local IP’s for nginx — you can limit this by setting the value as ‘<strong>listen 10.10.3.5:80;</strong>‘.</p>
<p><strong>proxy_pass http://10.10.6.230;</strong><br />
Here we are telling nginx where to find our content aka the backend server, this should be an IP and it is also important to not forget setting the ‘proxy_set_header Host’ option so that the backend server knows what vhost to serve.</p>
<p><strong>proxy_cache_valid</strong><br />
This allows us to define cache times based on HTTP status codes for our content, for 99% of traffic it will fall under the ’200 301 302 20m’ value. If you are running allot of dynamic content you may want to lower this from 20m to 10m or 5m, any lower defeats the purpose of caching. The ’404 1m’ value ensures that not found pages are not stored for long in case you are updating the site/have a temporary error but also prevent 404′s from choking up the backend server. Then the ‘any 15m’ value grabs all other content and caches it for 15m, again if you are running a very dynamic site you may want to lower this.</p>
<p><strong>proxy_cache_use_stale</strong><br />
When the cache has stale content, that is content which has expired but not yet been updated, nginx can serve this content in the event errors are encountered. Here we are telling nginx to serve stale cache data if there is an error/timeout/invalid header talking to the backend servers or if another nginx worker process is busy updating the cache. This is really useful in the event your web server crashes, as to clients they will receive data from the cache.</p>
<p><strong>location /admin</strong><br />
With this location statement we are telling nginx to take all requests to ‘http://myforums.com/admin’ and pass it off directly to our backend server with no further interaction — no caching.</p>
<p><strong>That’s it!</strong> You can start nginx by running ‘/usr/local/nginx/sbin/nginx’, it should not generate any errors if you did everything right! To start nginx on boot you can append the command into ‘/etc/rc.local’. All you have to do now is point the respective domain DNS records to the IP of the server running nginx and it will start proxy-caching for you. If you wanted to run nginx on the same host as your Apache server you could set Apache to listen on port 8080 and then adjust the ‘proxy_pass’ options accordingly as ‘proxy_pass http://127.0.0.1:8080;’.</p>
<p><strong>Extended Usage:</strong><br />
If you wanted to have nginx serve static content instead of Apache, since it is so horrible at it, we need to declare a new location option in our vhosts/*.conf file. We have two options here, we can either point nginx to a local path with our static content or have nginx cache our static content then retain it for longer periods of time — the later is far simpler.</p>
<p><strong>Serve static content from a local path:</strong></p>
<pre>        location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
            root   /home/myuser/public_html;
            expires 1d;
        }</pre>
<p>In the above, we are telling nginx that our static content is located at ‘/home/myuser/public_html’, paths must be relative!! When a user requests ‘http://www.mydomain.com/img/flyingpigs.jpg’, nginx will look for it at ‘/home/myuser/public_html/img/flyingpigs.jpg’. The expires option can have values in seconds, minutes, hours or days — if you have allot of dynamic images on your site then you might consider an option like 2h or 30m, anything lower defeats the purpose. Using this method has a slight performance benefit over the cache option below.</p>
<p><strong>Serve static content from cache:</strong></p>
<pre>        location ~* ^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$ {
             proxy_cache_valid 200 301 302 120m;
             expires 2d;
             proxy_pass http://10.10.6.230;
             proxy_cache one;
        }</pre>
<p>With this setup we are telling nginx to cache our static content just like we did with the parent site itself, except that we are defining an extended time period for which the content is valid/cached. The time values are, content is valid for 2h (nginx updates cache) and every 2 days the content expires (client browsers cache expires and requests again). Using this method is simple and does not require copying static content to a dedicated nginx host.</p>
<p>We can also do load balancing very easily with nginx, this is done by setting an alias for a group of servers, we then define this alias in place of addresses in our ‘proxy_pass’ settings. In the ‘upstream’ option shown below, we want to list all of our web servers that load should be distributed across:</p>
<pre>  upstream my_server_group {
    server 10.10.6.230:8000 weight=1;
    server 10.10.6.231:8000 weight=2 max_fails=3  fail_timeout=30s;
    server 10.10.6.15:8080 weight=2;
    server 10.10.6.17:8081
  }</pre>
<p>This must be placed in the ‘http { }’ section of the ‘conf/nginx.conf’ file, then the server group can be used in any vhost. To do this we would replace ‘proxy_pass http://208.76.83.135;’ with ‘proxy_pass http://my_server_group;’. The requests will be distributed across the server group in a round-robin fashion with respect to the weighted values, if any. If a request to one of the servers fails, nginx will try the next server until it finds a working server. In the event no working servers can be found, nginx will fall back to stale cache data and ultimately an error if that’s not available.</p>
<p><strong>Conclusion:</strong><br />
This has turned into a longer post than I had planned but oh well, I hope it proves to be useful. If you need any help on the configuration options, please check out <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://wiki.nginx.org/NginxModules#Nginx_Core_Modules" >http://wiki.nginx.org</a></noindex>, it covers just about everything one could need.</p>
<p>Although I noted this nginx setup is deployed on a Xen guest (CentOS 5.4, 2GB RAM &amp; 2 CPU cores), it proved to be so efficient, that these specs were overkill for it. You could easily run nginx on a 1GB guest with a single core, a recycled server or locally on the Apache server. I should also mention that I took apart the MySQL replication cluster and am now running with a single MySQL server without issue — down from 4.</p>
<p>&nbsp;</p>
<p>Author: <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://www.rfxn.com/nginx-caching-proxy/" title="r-fx networks"  target="_blank">R-fx Networks</a></noindex></p>
]]></content:encoded>
			<wfw:commentRss>http://zirkan.com/tips/nginx-caching-proxy.php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From Apache To nGinx</title>
		<link>http://zirkan.com/tips/from-apache-to-nginx.php</link>
		<comments>http://zirkan.com/tips/from-apache-to-nginx.php#comments</comments>
		<pubDate>Tue, 08 Nov 2011 20:27:30 +0000</pubDate>
		<dc:creator>zirkan</dc:creator>
				<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://zirkan.com/?p=460</guid>
		<description><![CDATA[So you’ve finally decided to make the switch from Apache to Nginx. You most likely did this for performance reasons. But why exactly is Nginx so much faster than the typical Apache setup of the prefork MPM and mod_php? The technical explanation is that Nginx is a non-blocking event based architecture while Apache is a blocking [...]]]></description>
			<content:encoded><![CDATA[<p>So you’ve finally decided to make the switch from Apache to Nginx. You most likely did this for performance reasons. But why exactly is Nginx so much faster than the typical Apache setup of the prefork MPM and mod_php? The technical explanation is that Nginx is a non-blocking event based architecture while Apache is a blocking process based architecture.</p>
<p>To <strong>simplify it heavily </strong>the theory is like this:<span id="more-460"></span></p>
<p><strong>Apache Prefork Processes:</strong></p>
<ul>
<li>Receive PHP request, send it to a process.</li>
<li>Process receives the request and pass it to PHP.</li>
<li>Receive an image request, see process is busy.</li>
<li>Process finishes PHP request, returns output.</li>
<li>Process gets image requests and returns the image.</li>
</ul>
<p>While the process is handling the request it is not capable of serving another request, this means the amount of requests you can do simultaneously is directly proportional to the amount of processes you have running. Now, if a process took up just a small bit of memory that would not be too big of an issue as you could run a lot of processes. However, the way a typical Apache + PHP setup has the PHP binary embedded directly into the Apache processes. This means Apache can talk to PHP incredibly fast and without much overhead, but it also means that the Apache process is going to be 25-50MB in size. Not just for requests for PHP requests, but also for all static file requests. This is because the processes keep PHP embedded at all times due to cost of spawning new processes. This effectively means you will be limited by the amount of memory you have as you can only run a small amount of processes and a lot of image requests can quickly make you hit your maximum amount of processes.</p>
<p>Compare this to the Nginx event based method.</p>
<p><strong>Nginx Event Based Processing:</strong></p>
<ul>
<li>Receive request, trigger events in a process.</li>
<li>The process handles all the events and returns the output</li>
</ul>
<p>On the surface it seems fairly similar, except there’s no blocking. This is because the process handles events in parallel. One connection is not allowed to affect another connection even if run simultaneously. This adds some limitations to how you can program the web server, but it makes for far faster processing as one process can now handle tons of simultaneous requests.</p>
<p>Remember those limitations, though? Yeah, they’ll affect how we, as users, have to use Nginx. For instance, we can no longer embed PHP into our Nginx process as PHP is not asynchronous. Essentially, if we embedded PHP into Nginx the event based architecture of Nginx would be rendered void as PHP would be blocking and connections would just pile up.</p>
<p>Since a web server isn’t all that desirable without the ability to use dynamic scripting languages Nginx has support for various communication protocols such as FastCGI, SCGI and UWSGI. Conveniently enough, PHP happens to support FastCGI, which means we can still use PHP.</p>
<p><strong>FastCGI Versus Embedding</strong></p>
<p>The thing that confuses most first time users of something not Apache is that suddenly they have to actually handle the PHP part themselves. Nginx takes a complete hands off approach to all dynamic scripting languages and reverse proxy situations. (more on this later)</p>
<p>With Apache you just configure it to use PHP, start it and forget about it. With Nginx you have to spawn a number of PHP processes and tell Nginx to talk to them. This has both advantages and disadvantages.</p>
<p>The primary advantage is that you now have complete separation of your web server and PHP. If you change something in PHP you don’t have to restart Nginx, only PHP. Similarly, if you want to restart Nginx then PHP keeps running. Since Nginx supports upgrading the binary and changing the configuration on-the-fly this means you can upgrade your web server or change its configuration without any down time at all.</p>
<p>The primary disadvantage is that you have to handle the spawning and process control of PHP yourself, or rather Nginx won’t do it for you. A year ago this was a bit troublesome. You had to use a script called spawn-fcgi to spawn the fastcgi processes and then monitor them with something secondary like Monit. Alternatively you could use a patch to the PHP source code called PHP-FPM – quite literally FastCGI Process Manager. As of PHP 5.3.3 PHP-FPM is now part of the PHP core, which means you don’t have to patch the source code yourself, but can just set a compile time configure flag. Naturally, most distribution repositories have a PHP build with PHP-FPM enabled as well. So really, this disadvantage is barely a disadvantage any more as PHP-FPM is a very cool thing in itself. More on that another day.</p>
<p>A second disadvantage, which is heavily disputed is that since the PHP process is no longer embedded there is an overhead in talking to PHP. This is used as an argument by some people as for why you should use Nginx to handle static files and Apache to handle the PHP files. Theoretically there is an overhead in talking with Apache as well, so I personally doubt there’s much of a disadvantage, but I don’t have the tests to back that up.</p>
<p><strong>The Configuration Differences</strong></p>
<p>Okay so we now know what the big picture is, time to understand how Apache and Nginx differs on a configure level. This is where we’ll actually spend most of our time so this is what is important to know about. I have to stress that it’s important to actually learn about Nginx. Nginx has undergone a huge amount of development in the last few years and as a result there is a lot of different advice out on various blogs. To be quite frank, a lot of it is bollocks and should be removed as it is often down right wrong. In general, if a tutorial or guide is making heavy use of ifs then avoid it, there are far better alternatives such as try_files, I’ll cover that a bit in this section.</p>
<p><strong>.htaccess</strong></p>
<p>The biggest headache for a lot of people is that they no longer have access to .htaccess. There is no way to change your Nginx configuration without issuing a reload command to Nginx. The effect can be simulated by using include directives in the main Nginx configuration file, but any change will not take effect until the configuration file has been reloaded. This is also the primary reason why Nginx is not very suited for shared hosting, not even in a situation where you reverse proxy to Apache.</p>
<p>There is no alternative in Nginx so if you want to use Nginx this is one thing you have to live with, in the beginning it might be annoying but after a few hours you really won’t notice or miss it.</p>
<p><strong>Apache &amp; Nginx Rewrites<br />
</strong></p>
<p>Typically in Apache you will specify your rewrites in .htaccess or at least in a global context so that they are always evaluated. Nginx provides locations to prevent this exact thing. We don’t want to execute something that we don’t need to, so if we need to rewrite the URI example.org/forum/index.php?topic=3 into forum.example.org/index.php?topic=3 we should use a location to ensure we only execute this rewrite when absolutely required.</p>
<p>Another thing about Nginx rewrites is that by default they are internal rewrites, which means that they won’t change the URI the browser sees. They will only do that if you specify the “redirect” or “permanent” rewrite flag or if you rewrite to an absolute URL including the http:// part.</p>
<p><strong>Apache RewriteCond</strong></p>
<p>Rewrite Conditions is something which doesn’t really exist in Nginx. Something you might see in Apache is the following:</p>
<pre>RewriteCond   %{HTTP_HOST}   ^example.org$   [NC]
RewriteRule   ^(.*)$   http://www.example.com/$1   [R=301,L]</pre>
<p>The directly translated Nginx equivalent would be</p>
<pre>if ($host != 'example.org' ) {
    rewrite  ^/(.*)$  <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://www.site.com/$1"  rel="nofollow" target="_blank">http://www.example.org/$1</a></noindex> permanent;
}</pre>
<p>I took this from an actual tutorial out there. This is wrong for two reasons. Most importantly Nginx does a lot of optimization to vhosts. If you use an if like this you miss out on that optimization as a request for example.org and www.example.org will both have to go to the vhost, then parse the if and then the regex. Less important is that you’re capturing data Nginx has already captured for you.</p>
<p>The Nginx way to do this is the following:</p>
<pre>server {
    server_name example.org;
    rewrite ^ http://www.example.org$request_uri? permanent;
}</pre>
<p>This way a request for example.org will not parse to the www.example.org server block, we won’t have to actually parse a regex since it’s just a starting character and nothing else, and the rewrite still uses the URI captured by Nginx.</p>
<p>Another popular RewriteCond is the following:</p>
<pre>rewritecond %{REQUEST_FILENAME}!-d
rewritecond %{REQUEST_FILENAME}!-f
rewrite ^ /index.php [L]</pre>
<p>Basically, if the requested file doesn’t exist and isn’t a directory then do execute a rewrite, this is often used to implement pretty URLs. In Nginx you’d do this like the following:</p>
<pre>location / {
    try_files $uri $uri/ /index.php$is_args$args;
}</pre>
<p>What this means is that it will first check if $uri exists, (in relation to your root directive) then it will check if $uri/ exists, which would be a directory. Finally, if none of these exists it will do an internal rewrite to index.php</p>
<p>A quick thing to note is that while ifs are usually discouraged there are some cases where they cannot be avoided. For example if you want to check the request method is GET before you send to the backend then you are forced to use if ($request_method = GET) This will usually work just fine and isn’t too bad considering there isn’t a more optimal way to do it.</p>
<p><strong>Using Apache and Nginx Together</strong></p>
<p>A common scenario is for people to use both Apache and Nginx. They’ll have Nginx handle the static files and then proxy the dynamic requests to PHP. This can be beneficial if you are not completely ready to ditch Apache, for instance if you have a legacy application relying on Apache or .htaccess files. There are also a few cases where Nginx alone cannot handle all use cases. A common one is when people need a HTTP front end for SVN. The Nginx WebDAV module supports only a limited set of the protocol so in this case you need to reverse proxy to Apache and let it handle it.</p>
<p>On the flip side, having Apache handle your dynamic requests introduces another layer of complexity in your server setup, causing more potential problem areas. Usually you don’t actually need Apache so there’s really no reason to keep it around as a crutch, in the long run it will benefit you more to use just one of them.</p>
<p>if you do decide to use both, and plenty of people do, then there are a few things you should know. I won’t cover how to configure Nginx for this as the Wiki is plenty resourceful there. But keep this in mind:</p>
<p>When you reverse proxy to Apache, Nginx will handle the connection, parse it and then create a new connection to Apache. It does <strong>not</strong> tunnel the connection so you have to specify which headers to pass on. Furthermore, the connection Nginx establishes is using HTTP/1.0, and not HTTP/1.1. This means things such as chunked encoding is not supported.</p>
<p>To make your reverse proxy experience as easy as possible you should therefore keep a few things in mind.</p>
<ul>
<li>Let Nginx handle SSL and keep the connection between Nginx and Apache in plain text. There is no reason to add the overhead of SSL unless you are afraid of a man-in-the-middle attack on your internal network.</li>
<li>Let Nginx handle the gzipping of content. Don’t gzip on the Apache side as that will most likely cause you some major headaches.</li>
</ul>
<p>If you want a more comprehensive guide for reverse proxying and are too lazy to read the wiki then see <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://kbeezie.com/view/apache-with-nginx/" title="Apache and Nginx Together"  target="_blank">kblessinggr’s Apache and Nginx Together guide</a></noindex>.</p>
<p><strong>A Note on Shared Hosting</strong></p>
<p>I mentioned earlier that Nginx isn’tt very suited for shared hosting. You might think that if you let Nginx handle just static files while proxying non-existing files and dynamic files to Apache then you’ll be good. This isn’t quite the case, though. As an example, consider basic authentication, if you want to have basic authentication on a static file then you will need to add it in the Nginx configuration, and users cannot do this without having to reload the configuration file. If you allow them to change it and reload it then they can make a mistake and ruin it for everyone.</p>
<p>Think <strong>very</strong> carefully about every aspect before you decide to use Nginx in your shared hosting setups.</p>
<p>&nbsp;</p>
<p>Credit goes entirely to <noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://blog.martinfjordvald.com/2011/02/nginx-primer-2-from-apache-to-nginx/" title="Nartin F"  target="_blank">Martin Fjordvald</a></noindex></p>
]]></content:encoded>
			<wfw:commentRss>http://zirkan.com/tips/from-apache-to-nginx.php/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Set Time in Linux Server Settings(CentOS/RHEL)</title>
		<link>http://zirkan.com/random/set-time-in-server-settings-centos.php</link>
		<comments>http://zirkan.com/random/set-time-in-server-settings-centos.php#comments</comments>
		<pubDate>Wed, 28 Sep 2011 16:53:23 +0000</pubDate>
		<dc:creator>zirkan</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://zirkan.com/?p=437</guid>
		<description><![CDATA[I have been looking for easy solution to set time on our servers, and here is the best one I found. &#160; First of all: you have to have root access to set this up. &#160; CentOS/RHEL has whole series of time zone files located at /usr/share/zoneinfo. So cd in the folder /usr/share/zoneinfo and select [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking for easy solution to set time on our servers, and here is the best one I found.<span id="more-437"></span><br />
&nbsp;<br />
First of all: you have to have root access to set this up.<br />
&nbsp;<br />
CentOS/RHEL has whole series of time zone files located at /usr/share/zoneinfo. So cd in the folder /usr/share/zoneinfo and  select the appropriate named timezone for your location. For my location, New York, USA, I actually have two that I can select from: America/New_York or US/Eastern. Note the appropriate folder and file for your timezone.<br />
&nbsp;<br />
The active timezone used on your system is in the /etc/localtime file. The default will vary depending on your server host but often seems to be EST or EDT (depending on the time of year you are checking).<br />
&nbsp;<br />
-First, make a backup of the existing localtime file. It’s always good practice to make backups of original config files.<br />
&nbsp;<br />
-mv /etc/localtime /etc/localtime.bak<br />
Next, create the link:<br />
&nbsp;<br />
-ln -s /usr/share/zoneinfo/<strong>US/Eastern</strong> /etc/localtime<br />
Make sure to replace “US/Eastern” with the directory and filename of the timezone you wish to use.<br />
&nbsp;<br />
-Run “date” from the command line, and ensure that the appropriate time, date, and timezone are reported.</p>
]]></content:encoded>
			<wfw:commentRss>http://zirkan.com/random/set-time-in-server-settings-centos.php/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>MySQL Cheat-Sheet</title>
		<link>http://zirkan.com/random/mysql.php</link>
		<comments>http://zirkan.com/random/mysql.php#comments</comments>
		<pubDate>Fri, 05 Aug 2011 11:35:12 +0000</pubDate>
		<dc:creator>zirkan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://baklach.net/themeforest/wordpress/nanica/?p=178</guid>
		<description><![CDATA[Here is the biggest cheat-sheet for MySQL you can find on the net nowadays, we have combined everything from terminal requests to queries from scripts and applications. So if you ever forget how to restore a backup without &#8220;phpmyadmin&#8221; or forgot the command to dump records from the table&#8230; you know where to find it. [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the biggest cheat-sheet for MySQL you can find on the net nowadays, we have combined everything from terminal requests to queries from scripts and applications. So if you ever forget how to restore a backup without &#8220;phpmyadmin&#8221; or forgot the command to dump records from the table&#8230; you know where to find it.<br />
<span id="more-178"></span><br />
&nbsp;<br />
&nbsp;<br />
<strong>To login (from unix shell) use -h only if needed.</strong></p>
<p># [mysql dir]/bin/mysql -h hostname -u root -p</p>
<p><strong>Create a database on the sql server.</strong></p>
<p>mysql&gt; create database [databasename];</p>
<p><strong>List all databases on the sql server.</strong></p>
<p>mysql&gt; show databases;</p>
<p><strong>Switch to a database.</strong></p>
<p>mysql&gt; use [db name];</p>
<p><strong>To see all the tables in the db.</strong></p>
<p>mysql&gt; show tables;</p>
<p><strong>To see database&#8217;s field formats.</strong></p>
<p>mysql&gt; describe [table name];</p>
<p><strong>To delete a db.</strong></p>
<p>mysql&gt; drop database [database name];</p>
<p><strong>To delete a table.</strong></p>
<p>mysql&gt; drop table [table name];</p>
<p><strong>Show all data in a table.</strong></p>
<p>mysql&gt; SELECT * FROM [table name];</p>
<p><strong>Returns the columns and column information pertaining to the designated table.</strong></p>
<p>mysql&gt; show columns from [table name];</p>
<p><strong>Show certain selected rows with the value &#8220;whatever&#8221;.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE [field name] = &#8220;whatever&#8221;;</p>
<p><strong>Show all records containing the name &#8220;Bob&#8221; AND the phone number &#8217;3444444&#8242;.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE name = &#8220;Bob&#8221; AND phone_number = &#8217;3444444&#8242;;</p>
<p><strong>Show all records not containing the name &#8220;Bob&#8221; AND the phone number &#8217;3444444&#8242; order by the phone_number field.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE name != &#8220;Bob&#8221; AND phone_number = &#8217;3444444&#8242; order by phone_number;</p>
<p><strong>Show all records starting with the letters &#8216;bob&#8217; AND the phone number &#8217;3444444&#8242;.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE name like &#8220;Bob%&#8221; AND phone_number = &#8217;3444444&#8242;;</p>
<p><strong>Show all records starting with the letters &#8216;bob&#8217; AND the phone number &#8217;3444444&#8242; limit to records 1 through 5.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE name like &#8220;Bob%&#8221; AND phone_number = &#8217;3444444&#8242; limit 1,5;</p>
<p><strong>Use a regular expression to find records. Use &#8220;REGEXP BINARY&#8221; to force case-sensitivity. This finds any record beginning with a.</strong></p>
<p>mysql&gt; SELECT * FROM [table name] WHERE rec RLIKE &#8220;^a&#8221;;</p>
<p><strong>Show unique records.</strong></p>
<p>mysql&gt; SELECT DISTINCT [column name] FROM [table name];</p>
<p><strong>Show selected records sorted in an ascending (asc) or descending (desc).</strong></p>
<p>mysql&gt; SELECT [col1],[col2] FROM [table name] ORDER BY [col2] DESC;</p>
<p><strong>Return number of rows.</strong></p>
<p>mysql&gt; SELECT COUNT(*) FROM [table name];</p>
<p><strong>Sum column.</strong></p>
<p>mysql&gt; SELECT SUM(*) FROM [table name];</p>
<p><strong>Join tables on common columns.</strong></p>
<p>mysql&gt; select lookup.illustrationid, lookup.personid,person.birthday from lookup left join person on lookup.personid=person.personid=statement to join birthday in person table with primary illustration id;</p>
<p><strong>Creating a new user. Login as root. Switch to the MySQL db. Make the user. Update privs.</strong></p>
<p># mysql -u root -p<br />
mysql&gt; use mysql;<br />
mysql&gt; INSERT INTO user (Host,User,Password) VALUES(&#8216;%&#8217;,'username&#8217;,PASSWORD(&#8216;password&#8217;));<br />
mysql&gt; flush privileges;</p>
<p><strong>Change a users password from unix shell.</strong></p>
<p># [mysql dir]/bin/mysqladmin -u username -h hostname.blah.org -p password &#8216;new-password&#8217;</p>
<p><strong>Change a users password from MySQL prompt. Login as root. Set the password. Update privs.</strong></p>
<p># mysql -u root -p<br />
mysql&gt; SET PASSWORD FOR &#8216;user&#8217;@'hostname&#8217; = PASSWORD(&#8216;passwordhere&#8217;);<br />
mysql&gt; flush privileges;</p>
<p><strong>Recover a MySQL root password. Stop the MySQL server process. Start again with no grant tables. Login to MySQL as root. Set new password. Exit MySQL and restart MySQL server.</strong></p>
<p># /etc/init.d/mysql stop<br />
# mysqld_safe &#8211;skip-grant-tables &amp;<br />
# mysql -u root<br />
mysql&gt; use mysql;<br />
mysql&gt; update user set password=PASSWORD(&#8220;newrootpassword&#8221;) where User=&#8217;root&#8217;;<br />
mysql&gt; flush privileges;<br />
mysql&gt; quit<br />
# /etc/init.d/mysql stop<br />
# /etc/init.d/mysql start</p>
<p><strong>Set a root password if there is on root password.</strong></p>
<p># mysqladmin -u root password newpassword</p>
<p><strong>Update a root password.</strong></p>
<p># mysqladmin -u root -p oldpassword newpassword</p>
<p><strong>Allow the user &#8220;bob&#8221; to connect to the server from localhost using the password &#8220;passwd&#8221;. Login as root. Switch to the MySQL db. Give privs. Update privs.</strong></p>
<p># mysql -u root -p<br />
mysql&gt; use mysql;<br />
mysql&gt; grant usage on *.* to bob@localhost identified by &#8216;passwd&#8217;;<br />
mysql&gt; flush privileges;</p>
<p><strong>Give user privilages for a db. Login as root. Switch to the MySQL db. Grant privs. Update privs.</strong></p>
<p># mysql -u root -p<br />
mysql&gt; use mysql;<br />
mysql&gt; INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv) VALUES (&#8216;%&#8217;,'databasename&#8217;,'username&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'Y&#8217;,'N&#8217;);<br />
mysql&gt; flush privileges;</p>
<p>or</p>
<p>mysql&gt; grant all privileges on databasename.* to username@localhost;<br />
mysql&gt; flush privileges;</p>
<p><strong>To update info already in a table.</strong></p>
<p>mysql&gt; UPDATE [table name] SET Select_priv = &#8216;Y&#8217;,Insert_priv = &#8216;Y&#8217;,Update_priv = &#8216;Y&#8217; where [field name] = &#8216;user&#8217;;</p>
<p><strong>Delete a row(s) from a table.</strong></p>
<p>mysql&gt; DELETE from [table name] where [field name] = &#8216;whatever&#8217;;</p>
<p><strong>Update database permissions/privilages.</strong></p>
<p>mysql&gt; flush privileges;</p>
<p><strong>Delete a column.</strong></p>
<p>mysql&gt; alter table [table name] drop column [column name];</p>
<p><strong>Add a new column to db.</strong></p>
<p>mysql&gt; alter table [table name] add column [new column name] varchar (20);</p>
<p><strong>Change column name.</strong></p>
<p>mysql&gt; alter table [table name] change [old column name] [new column name] varchar (50);</p>
<p><strong>Make a unique column so you get no dupes.</strong></p>
<p>mysql&gt; alter table [table name] add unique ([column name]);</p>
<p><strong>Make a column bigger.</strong></p>
<p>mysql&gt; alter table [table name] modify [column name] VARCHAR(3);</p>
<p><strong>Delete unique from table.</strong></p>
<p>mysql&gt; alter table [table name] drop index [colmn name];</p>
<p><strong>Load a CSV file into a table.</strong></p>
<p>mysql&gt; LOAD DATA INFILE &#8216;/tmp/filename.csv&#8217; replace INTO TABLE [table name] FIELDS TERMINATED BY &#8216;,&#8217; LINES TERMINATED BY &#8216;\n&#8217; (field1,field2,field3);</p>
<p><strong>Dump all databases for backup. Backup file is sql commands to recreate all db&#8217;s.</strong></p>
<p># [mysql dir]/bin/mysqldump -u root -ppassword &#8211;opt &gt;/tmp/alldatabases.sql</p>
<p><strong>Dump one database for backup.</strong></p>
<p># [mysql dir]/bin/mysqldump -u username -ppassword &#8211;databases databasename &gt;/tmp/databasename.sql</p>
<p><strong>Dump a table from a database.</strong></p>
<p># [mysql dir]/bin/mysqldump -c -u username -ppassword databasename tablename &gt; /tmp/databasename.tablename.sql</p>
<p><strong>Restore database (or database table) from backup.</strong></p>
<p># [mysql dir]/bin/mysql -u username -ppassword databasename &lt; /tmp/databasename.sql</p>
<p><strong>Create Table Example 1.</strong></p>
<p>mysql&gt; CREATE TABLE [table name] (firstname VARCHAR(20), middleinitial VARCHAR(3), lastname VARCHAR(35),suffix VARCHAR(3),officeid VARCHAR(10),userid VARCHAR(15),username VARCHAR(8),email VARCHAR(35),phone VARCHAR(25), groups VARCHAR(15),datestamp DATE,timestamp time,pgpemail VARCHAR(255));</p>
<p><strong>Create Table Example 2.</strong></p>
<p>mysql&gt; create table [table name] (personid int(50) not null auto_increment primary key,firstname varchar(35),middlename varchar(50),lastnamevarchar(50) default &#8216;bato&#8217;);</p>
<p><strong>MYSQL Statements and clauses</strong></p>
<p>ALTER DATABASE</p>
<p>&nbsp;</p>
<p>ALTER TABLE</p>
<p>&nbsp;</p>
<p>ALTER VIEW</p>
<p>&nbsp;</p>
<p>ANALYZE TABLE</p>
<p>&nbsp;</p>
<p>BACKUP TABLE</p>
<p>&nbsp;</p>
<p>CACHE INDEX</p>
<p>&nbsp;</p>
<p>CHANGE MASTER TO</p>
<p>&nbsp;</p>
<p>CHECK TABLE</p>
<p>&nbsp;</p>
<p>CHECKSUM TABLE</p>
<p>&nbsp;</p>
<p>COMMIT</p>
<p>&nbsp;</p>
<p>CREATE DATABASE</p>
<p>&nbsp;</p>
<p>CREATE INDEX</p>
<p>&nbsp;</p>
<p>CREATE TABLE</p>
<p>&nbsp;</p>
<p>CREATE VIEW</p>
<p>&nbsp;</p>
<p>DELETE</p>
<p>&nbsp;</p>
<p>DESCRIBE</p>
<p>&nbsp;</p>
<p>DO</p>
<p>&nbsp;</p>
<p>DROP DATABASE</p>
<p>&nbsp;</p>
<p>DROP INDEX</p>
<p>&nbsp;</p>
<p>DROP TABLE</p>
<p>&nbsp;</p>
<p>DROP USER</p>
<p>&nbsp;</p>
<p>DROP VIEW</p>
<p>&nbsp;</p>
<p>EXPLAIN</p>
<p>&nbsp;</p>
<p>FLUSH</p>
<p>&nbsp;</p>
<p>GRANT</p>
<p>&nbsp;</p>
<p>HANDLER</p>
<p>&nbsp;</p>
<p>INSERT</p>
<p>&nbsp;</p>
<p>JOIN</p>
<p>&nbsp;</p>
<p>KILL</p>
<p>&nbsp;</p>
<p>LOAD DATA FROM MASTER</p>
<p>&nbsp;</p>
<p>LOAD DATA INFILE</p>
<p>&nbsp;</p>
<p>LOAD INDEX INTO CACHE</p>
<p>&nbsp;</p>
<p>LOAD TABLE&#8230;FROM MASTER</p>
<p>&nbsp;</p>
<p>LOCK TABLES</p>
<p>&nbsp;</p>
<p>OPTIMIZE TABLE</p>
<p>&nbsp;</p>
<p>PURGE MASTER LOGS</p>
<p>&nbsp;</p>
<p>RENAME TABLE</p>
<p>&nbsp;</p>
<p>REPAIR TABLE</p>
<p>&nbsp;</p>
<p>REPLACE</p>
<p>&nbsp;</p>
<p>RESET</p>
<p>&nbsp;</p>
<p>RESET MASTER</p>
<p>&nbsp;</p>
<p>RESET SLAVE</p>
<p>&nbsp;</p>
<p>RESTORE TABLE</p>
<p>&nbsp;</p>
<p>REVOKE</p>
<p>&nbsp;</p>
<p>ROLLBACK</p>
<p>&nbsp;</p>
<p>ROLLBACK TO SAVEPOINT</p>
<p>&nbsp;</p>
<p>SAVEPOINT</p>
<p>&nbsp;</p>
<p>SELECT</p>
<p>&nbsp;</p>
<p>SET</p>
<p>&nbsp;</p>
<p>SET PASSWORD</p>
<p>&nbsp;</p>
<p>SET SQL_LOG_BIN</p>
<p>&nbsp;</p>
<p>SET TRANSACTION</p>
<p>&nbsp;</p>
<p>SHOW BINLOG EVENTS</p>
<p>&nbsp;</p>
<p>SHOW CHARACTER SET</p>
<p>&nbsp;</p>
<p>SHOW COLLATION</p>
<p>&nbsp;</p>
<p>SHOW COLUMNS</p>
<p>&nbsp;</p>
<p>SHOW CREATE DATABASE</p>
<p>&nbsp;</p>
<p>SHOW CREATE TABLE</p>
<p>&nbsp;</p>
<p>SHOW CREATE VIEW</p>
<p>&nbsp;</p>
<p>SHOW DATABASES</p>
<p>&nbsp;</p>
<p>SHOW ENGINES</p>
<p>&nbsp;</p>
<p>SHOW ERRORS</p>
<p>&nbsp;</p>
<p>SHOW GRANTS</p>
<p>&nbsp;</p>
<p>SHOW INDEX</p>
<p>&nbsp;</p>
<p>SHOW INNODB STATUS</p>
<p>&nbsp;</p>
<p>SHOW LOGS</p>
<p>&nbsp;</p>
<p>SHOW MASTER LOGS</p>
<p>&nbsp;</p>
<p>SHOW MASTER STATUS</p>
<p>&nbsp;</p>
<p>SHOW PRIVILEGES</p>
<p>&nbsp;</p>
<p>SHOW PROCESSLIST</p>
<p>&nbsp;</p>
<p>SHOW SLAVE HOSTS</p>
<p>&nbsp;</p>
<p>SHOW SLAVE STATUS</p>
<p>&nbsp;</p>
<p>SHOW STATUS</p>
<p>&nbsp;</p>
<p>SHOW TABLE STATUS</p>
<p>&nbsp;</p>
<p>SHOW TABLES</p>
<p>&nbsp;</p>
<p>SHOW VARIABLES</p>
<p>&nbsp;</p>
<p>SHOW WARNINGS</p>
<p>&nbsp;</p>
<p>START SLAVE</p>
<p>&nbsp;</p>
<p>START TRANSACTION</p>
<p>&nbsp;</p>
<p>STOP SLAVE</p>
<p>&nbsp;</p>
<p>TRUNCATE TABLE</p>
<p>&nbsp;</p>
<p>UNION</p>
<p>&nbsp;</p>
<p>UNLOCK TABLES</p>
<p>&nbsp;</p>
<p>USE</p>
<p>&nbsp;</p>
<p><strong>String Functions</strong></p>
<p>AES_DECRYPT</p>
<p>&nbsp;</p>
<p>AES_ENCRYPT</p>
<p>&nbsp;</p>
<p>ASCII</p>
<p>&nbsp;</p>
<p>BIN</p>
<p>&nbsp;</p>
<p>BINARY</p>
<p>&nbsp;</p>
<p>BIT_LENGTH</p>
<p>&nbsp;</p>
<p>CHAR</p>
<p>&nbsp;</p>
<p>CHAR_LENGTH</p>
<p>&nbsp;</p>
<p>CHARACTER_LENGTH</p>
<p>&nbsp;</p>
<p>COMPRESS</p>
<p>&nbsp;</p>
<p>CONCAT</p>
<p>&nbsp;</p>
<p>CONCAT_WS</p>
<p>&nbsp;</p>
<p>CONV</p>
<p>&nbsp;</p>
<p>DECODE</p>
<p>&nbsp;</p>
<p>DES_DECRYPT</p>
<p>&nbsp;</p>
<p>DES_ENCRYPT</p>
<p>&nbsp;</p>
<p>ELT</p>
<p>&nbsp;</p>
<p>ENCODE</p>
<p>&nbsp;</p>
<p>ENCRYPT</p>
<p>&nbsp;</p>
<p>EXPORT_SET</p>
<p>&nbsp;</p>
<p>FIELD</p>
<p>&nbsp;</p>
<p>FIND_IN_SET</p>
<p>&nbsp;</p>
<p>HEX</p>
<p>&nbsp;</p>
<p>INET_ATON</p>
<p>&nbsp;</p>
<p>INET_NTOA</p>
<p>&nbsp;</p>
<p>INSERT</p>
<p>&nbsp;</p>
<p>INSTR</p>
<p>&nbsp;</p>
<p>LCASE</p>
<p>&nbsp;</p>
<p>LEFT</p>
<p>&nbsp;</p>
<p>LENGTH</p>
<p>&nbsp;</p>
<p>LOAD_FILE</p>
<p>&nbsp;</p>
<p>LOCATE</p>
<p>&nbsp;</p>
<p>LOWER</p>
<p>&nbsp;</p>
<p>LPAD</p>
<p>&nbsp;</p>
<p>LTRIM</p>
<p>&nbsp;</p>
<p>MAKE_SET</p>
<p>&nbsp;</p>
<p>MATCH    AGAINST</p>
<p>&nbsp;</p>
<p>MD5</p>
<p>&nbsp;</p>
<p>MID</p>
<p>&nbsp;</p>
<p>OCT</p>
<p>&nbsp;</p>
<p>OCTET_LENGTH</p>
<p>&nbsp;</p>
<p>OLD_PASSWORD</p>
<p>&nbsp;</p>
<p>ORD</p>
<p>&nbsp;</p>
<p>PASSWORD</p>
<p>&nbsp;</p>
<p>POSITION</p>
<p>&nbsp;</p>
<p>QUOTE</p>
<p>&nbsp;</p>
<p>REPEAT</p>
<p>&nbsp;</p>
<p>REPLACE</p>
<p>&nbsp;</p>
<p>REVERSE</p>
<p>&nbsp;</p>
<p>RIGHT</p>
<p>&nbsp;</p>
<p>RPAD</p>
<p>&nbsp;</p>
<p>RTRIM</p>
<p>&nbsp;</p>
<p>SHA</p>
<p>&nbsp;</p>
<p>SHA1</p>
<p>&nbsp;</p>
<p>SOUNDEX</p>
<p>&nbsp;</p>
<p>SPACE</p>
<p>&nbsp;</p>
<p>STRCMP</p>
<p>&nbsp;</p>
<p>SUBSTRING</p>
<p>&nbsp;</p>
<p>SUBSTRING_INDEX</p>
<p>&nbsp;</p>
<p>TRIM</p>
<p>&nbsp;</p>
<p>UCASE</p>
<p>&nbsp;</p>
<p>UNCOMPRESS</p>
<p>&nbsp;</p>
<p>UNCOMPRESSED_LENGTH</p>
<p>&nbsp;</p>
<p>UNHEX</p>
<p>&nbsp;</p>
<p>UPPER</p>
<p>&nbsp;</p>
<p><strong>Date and Time Functions</strong></p>
<p>ADDDATE</p>
<p>&nbsp;</p>
<p>ADDTIME</p>
<p>&nbsp;</p>
<p>CONVERT_TZ</p>
<p>&nbsp;</p>
<p>CURDATE</p>
<p>&nbsp;</p>
<p>CURRENT_DATE</p>
<p>&nbsp;</p>
<p>CURRENT_TIME</p>
<p>&nbsp;</p>
<p>CURRENT_TIMESTAMP</p>
<p>&nbsp;</p>
<p>CURTIME</p>
<p>&nbsp;</p>
<p>DATE</p>
<p>&nbsp;</p>
<p>DATE_ADD</p>
<p>&nbsp;</p>
<p>DATE_FORMAT</p>
<p>&nbsp;</p>
<p>DATE_SUB</p>
<p>&nbsp;</p>
<p>DATEDIFF</p>
<p>&nbsp;</p>
<p>DAY</p>
<p>&nbsp;</p>
<p>DAYNAME</p>
<p>&nbsp;</p>
<p>DAYOFMONTH</p>
<p>&nbsp;</p>
<p>DAYOFWEEK</p>
<p>&nbsp;</p>
<p>DAYOFYEAR</p>
<p>&nbsp;</p>
<p>EXTRACT</p>
<p>&nbsp;</p>
<p>FROM_DAYS</p>
<p>&nbsp;</p>
<p>FROM_UNIXTIME</p>
<p>&nbsp;</p>
<p>GET_FORMAT</p>
<p>&nbsp;</p>
<p>HOUR</p>
<p>&nbsp;</p>
<p>LAST_DAY</p>
<p>&nbsp;</p>
<p>LOCALTIME</p>
<p>&nbsp;</p>
<p>LOCALTIMESTAMP</p>
<p>&nbsp;</p>
<p>MAKEDATE</p>
<p>&nbsp;</p>
<p>MAKETIME</p>
<p>&nbsp;</p>
<p>MICROSECOND</p>
<p>&nbsp;</p>
<p>MINUTE</p>
<p>&nbsp;</p>
<p>MONTH</p>
<p>&nbsp;</p>
<p>MONTHNAME</p>
<p>&nbsp;</p>
<p>NOW</p>
<p>&nbsp;</p>
<p>PERIOD_ADD</p>
<p>&nbsp;</p>
<p>PERIOD_DIFF</p>
<p>&nbsp;</p>
<p>QUARTER</p>
<p>&nbsp;</p>
<p>SEC_TO_TIME</p>
<p>&nbsp;</p>
<p>SECOND</p>
<p>&nbsp;</p>
<p>STR_TO_DATE</p>
<p>&nbsp;</p>
<p>SUBDATE</p>
<p>&nbsp;</p>
<p>SUBTIME</p>
<p>&nbsp;</p>
<p>SYSDATE</p>
<p>&nbsp;</p>
<p>TIME</p>
<p>&nbsp;</p>
<p>TIMEDIFF</p>
<p>&nbsp;</p>
<p>TIMESTAMP</p>
<p>&nbsp;</p>
<p>TIMESTAMPDIFF</p>
<p>&nbsp;</p>
<p>TIMESTAMPADD</p>
<p>&nbsp;</p>
<p>TIME_FORMAT</p>
<p>&nbsp;</p>
<p>TIME_TO_SEC</p>
<p>&nbsp;</p>
<p>TO_DAYS</p>
<p>&nbsp;</p>
<p>UNIX_TIMESTAMP</p>
<p>&nbsp;</p>
<p>UTC_DATE</p>
<p>&nbsp;</p>
<p>UTC_TIME</p>
<p>&nbsp;</p>
<p>UTC_TIMESTAMP</p>
<p>&nbsp;</p>
<p>WEEK</p>
<p>&nbsp;</p>
<p>WEEKDAY</p>
<p>&nbsp;</p>
<p>WEEKOFYEAR</p>
<p>&nbsp;</p>
<p>YEAR</p>
<p>&nbsp;</p>
<p>YEARWEEK</p>
<p>&nbsp;</p>
<p><strong>Mathematical and Aggregate Functions</strong></p>
<p>ABS</p>
<p>&nbsp;</p>
<p>ACOS</p>
<p>&nbsp;</p>
<p>ASIN</p>
<p>&nbsp;</p>
<p>ATAN</p>
<p>&nbsp;</p>
<p>ATAN2</p>
<p>&nbsp;</p>
<p>AVG</p>
<p>&nbsp;</p>
<p>BIT_AND</p>
<p>&nbsp;</p>
<p>BIT_OR</p>
<p>&nbsp;</p>
<p>BIT_XOR</p>
<p>&nbsp;</p>
<p>CEIL</p>
<p>&nbsp;</p>
<p>CEILING</p>
<p>&nbsp;</p>
<p>COS</p>
<p>&nbsp;</p>
<p>COT</p>
<p>&nbsp;</p>
<p>COUNT</p>
<p>&nbsp;</p>
<p>CRC32</p>
<p>&nbsp;</p>
<p>DEGREES</p>
<p>&nbsp;</p>
<p>EXP</p>
<p>&nbsp;</p>
<p>FLOOR</p>
<p>&nbsp;</p>
<p>FORMAT</p>
<p>&nbsp;</p>
<p>GREATEST</p>
<p>&nbsp;</p>
<p>GROUP_CONCAT</p>
<p>&nbsp;</p>
<p>LEAST</p>
<p>&nbsp;</p>
<p>LN</p>
<p>&nbsp;</p>
<p>LOG</p>
<p>&nbsp;</p>
<p>LOG2</p>
<p>&nbsp;</p>
<p>LOG10</p>
<p>&nbsp;</p>
<p>MAX</p>
<p>&nbsp;</p>
<p>MIN</p>
<p>&nbsp;</p>
<p>MOD</p>
<p>&nbsp;</p>
<p>PI</p>
<p>&nbsp;</p>
<p>POW</p>
<p>&nbsp;</p>
<p>POWER</p>
<p>&nbsp;</p>
<p>RADIANS</p>
<p>&nbsp;</p>
<p>RAND</p>
<p>&nbsp;</p>
<p>ROUND</p>
<p>&nbsp;</p>
<p>SIGN</p>
<p>&nbsp;</p>
<p>SIN</p>
<p>&nbsp;</p>
<p>SQRT</p>
<p>&nbsp;</p>
<p>STD</p>
<p>&nbsp;</p>
<p>STDDEV</p>
<p>&nbsp;</p>
<p>SUM</p>
<p>&nbsp;</p>
<p>TAN</p>
<p>&nbsp;</p>
<p>TRUNCATE</p>
<p>&nbsp;</p>
<p>VARIANCE</p>
<p>&nbsp;</p>
<p><strong>Flow Control Functions</strong></p>
<p>CASE</p>
<p>&nbsp;</p>
<p>IF</p>
<p>&nbsp;</p>
<p>IFNULL</p>
<p>&nbsp;</p>
<p>NULLIF</p>
<p>&nbsp;</p>
<p><strong>Command-Line Utilities</strong></p>
<p>comp_err</p>
<p>&nbsp;</p>
<p>isamchk</p>
<p>&nbsp;</p>
<p>make_binary_distribution</p>
<p>&nbsp;</p>
<p>msql2mysql</p>
<p>&nbsp;</p>
<p>my_print_defaults</p>
<p>&nbsp;</p>
<p>myisamchk</p>
<p>&nbsp;</p>
<p>myisamlog</p>
<p>&nbsp;</p>
<p>myisampack</p>
<p>&nbsp;</p>
<p>mysqlaccess</p>
<p>&nbsp;</p>
<p>mysqladmin</p>
<p>&nbsp;</p>
<p>mysqlbinlog</p>
<p>&nbsp;</p>
<p>mysqlbug</p>
<p>&nbsp;</p>
<p>mysqlcheck</p>
<p>&nbsp;</p>
<p>mysqldump</p>
<p>&nbsp;</p>
<p>mysqldumpslow</p>
<p>&nbsp;</p>
<p>mysqlhotcopy</p>
<p>&nbsp;</p>
<p>mysqlimport</p>
<p>&nbsp;</p>
<p>mysqlshow</p>
<p>&nbsp;</p>
<p>perror</p>
<p>&nbsp;</p>
<p><strong>Perl API &#8211; using functions and methods built into the Perl DBI with MySQL</strong></p>
<p>available_drivers</p>
<p>&nbsp;</p>
<p>begin_work</p>
<p>&nbsp;</p>
<p>bind_col</p>
<p>&nbsp;</p>
<p>bind_columns</p>
<p>&nbsp;</p>
<p>bind_param</p>
<p>&nbsp;</p>
<p>bind_param_array</p>
<p>&nbsp;</p>
<p>bind_param_inout</p>
<p>&nbsp;</p>
<p>can</p>
<p>&nbsp;</p>
<p>clone</p>
<p>&nbsp;</p>
<p>column_info</p>
<p>&nbsp;</p>
<p>commit</p>
<p>&nbsp;</p>
<p>connect</p>
<p>&nbsp;</p>
<p>connect_cached</p>
<p>&nbsp;</p>
<p>data_sources</p>
<p>&nbsp;</p>
<p>disconnect</p>
<p>&nbsp;</p>
<p>do</p>
<p>&nbsp;</p>
<p>dump_results</p>
<p>&nbsp;</p>
<p>err</p>
<p>&nbsp;</p>
<p>errstr</p>
<p>&nbsp;</p>
<p>execute</p>
<p>&nbsp;</p>
<p>execute_array</p>
<p>&nbsp;</p>
<p>execute_for_fetch</p>
<p>&nbsp;</p>
<p>fetch</p>
<p>&nbsp;</p>
<p>fetchall_arrayref</p>
<p>&nbsp;</p>
<p>fetchall_hashref</p>
<p>&nbsp;</p>
<p>fetchrow_array</p>
<p>&nbsp;</p>
<p>fetchrow_arrayref</p>
<p>&nbsp;</p>
<p>fetchrow_hashref</p>
<p>&nbsp;</p>
<p>finish</p>
<p>&nbsp;</p>
<p>foreign_key_info</p>
<p>&nbsp;</p>
<p>func</p>
<p>&nbsp;</p>
<p>get_info</p>
<p>&nbsp;</p>
<p>installed_versions</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>last_insert_id</p>
<p>&nbsp;</p>
<p>looks_like_number</p>
<p>&nbsp;</p>
<p>neat</p>
<p>&nbsp;</p>
<p>neat_list</p>
<p>&nbsp;</p>
<p>parse_dsn</p>
<p>&nbsp;</p>
<p>parse_trace_flag</p>
<p>&nbsp;</p>
<p>parse_trace_flags</p>
<p>&nbsp;</p>
<p>ping</p>
<p>&nbsp;</p>
<p>prepare</p>
<p>&nbsp;</p>
<p>prepare_cached</p>
<p>&nbsp;</p>
<p>primary_key</p>
<p>&nbsp;</p>
<p>primary_key_info</p>
<p>&nbsp;</p>
<p>quote</p>
<p>&nbsp;</p>
<p>quote_identifier</p>
<p>&nbsp;</p>
<p>rollback</p>
<p>&nbsp;</p>
<p>rows</p>
<p>&nbsp;</p>
<p>selectall_arrayref</p>
<p>&nbsp;</p>
<p>selectall_hashref</p>
<p>&nbsp;</p>
<p>selectcol_arrayref</p>
<p>&nbsp;</p>
<p>selectrow_array</p>
<p>&nbsp;</p>
<p>selectrow_arrayref</p>
<p>&nbsp;</p>
<p>selectrow_hashref</p>
<p>&nbsp;</p>
<p>set_err</p>
<p>&nbsp;</p>
<p>state</p>
<p>&nbsp;</p>
<p>table_info</p>
<p>&nbsp;</p>
<p>table_info_all</p>
<p>&nbsp;</p>
<p>tables</p>
<p>&nbsp;</p>
<p>trace</p>
<p>&nbsp;</p>
<p>trace_msg</p>
<p>&nbsp;</p>
<p>type_info</p>
<p>&nbsp;</p>
<p>type_info_all</p>
<p>&nbsp;</p>
<p>Attributes for Handles</p>
<p>&nbsp;</p>
<p><strong>PHP API &#8211; using functions built into PHP with MySQL</strong></p>
<p>mysql_affected_rows</p>
<p>&nbsp;</p>
<p>mysql_change_user</p>
<p>&nbsp;</p>
<p>mysql_client_encoding</p>
<p>&nbsp;</p>
<p>mysql_close</p>
<p>&nbsp;</p>
<p>mysql_connect</p>
<p>&nbsp;</p>
<p>mysql_create_db</p>
<p>&nbsp;</p>
<p>mysql_data_seek</p>
<p>&nbsp;</p>
<p>mysql_db_name</p>
<p>&nbsp;</p>
<p>mysql_db_query</p>
<p>&nbsp;</p>
<p>mysql_drop_db</p>
<p>&nbsp;</p>
<p>mysql_errno</p>
<p>&nbsp;</p>
<p>mysql_error</p>
<p>&nbsp;</p>
<p>mysql_escape_string</p>
<p>&nbsp;</p>
<p>mysql_fetch_array</p>
<p>&nbsp;</p>
<p>mysql_fetch_assoc</p>
<p>&nbsp;</p>
<p>mysql_fetch_field</p>
<p>&nbsp;</p>
<p>mysql_fetch_lengths</p>
<p>&nbsp;</p>
<p>mysql_fetch_object</p>
<p>&nbsp;</p>
<p>mysql_fetch_row</p>
<p>&nbsp;</p>
<p>mysql_field_flags</p>
<p>&nbsp;</p>
<p>mysql_field_len</p>
<p>&nbsp;</p>
<p>mysql_field_name</p>
<p>&nbsp;</p>
<p>mysql_field_seek</p>
<p>&nbsp;</p>
<p>mysql_field_table</p>
<p>&nbsp;</p>
<p>mysql_field_type</p>
<p>&nbsp;</p>
<p>mysql_free_result</p>
<p>&nbsp;</p>
<p>mysql_get_client_info</p>
<p>&nbsp;</p>
<p>mysql_get_host_info</p>
<p>&nbsp;</p>
<p>mysql_get_proto_info</p>
<p>&nbsp;</p>
<p>mysql_get_server_info</p>
<p>&nbsp;</p>
<p>mysql_info</p>
<p>&nbsp;</p>
<p>mysql_insert_id</p>
<p>&nbsp;</p>
<p>mysql_list_dbs</p>
<p>&nbsp;</p>
<p>mysql_list_fields</p>
<p>&nbsp;</p>
<p>mysql_list_processes</p>
<p>&nbsp;</p>
<p>mysql_list_tables</p>
<p>&nbsp;</p>
<p>mysql_num_fields</p>
<p>&nbsp;</p>
<p>mysql_num_rows</p>
<p>&nbsp;</p>
<p>mysql_pconnect</p>
<p>&nbsp;</p>
<p>mysql_ping</p>
<p>&nbsp;</p>
<p>mysql_query</p>
<p>&nbsp;</p>
<p>mysql_real_escape_string</p>
<p>&nbsp;</p>
<p>mysql_result</p>
<p>&nbsp;</p>
<p>mysql_select_db</p>
<p>&nbsp;</p>
<p>mysql_stat</p>
<p>&nbsp;</p>
<p>mysql_tablename</p>
<p>&nbsp;</p>
<p>mysql_thread_id</p>
<p>&nbsp;</p>
<p>mysql_unbuffered_query</p>
<p>&nbsp;<br />
<div class="full_width"> </div></p>
<p>&nbsp;</p>
<div class="button_cont"><noindex><a target="_blank" rel="nofollow" href="http://zirkan.com/goto/http://c.zirkan.com/public/index.php/documents/"  class="button orange"><span>Based on Zirkan Internal Documentation</span></a></noindex></div>
<div class="full_width"> </div>
]]></content:encoded>
			<wfw:commentRss>http://zirkan.com/random/mysql.php/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

