Jun 3 2013

Install and Configure memcache on windows

Kailash Yadav

After some research I found that there is a Win32 binary version of memcached available here.

So go there and download binary version to your computer. When downloaded, extract the file to folder memcahced on your C drive.

You should get only one file named memcached.exe. Now we need to install this as a service.

To install Memcached as a service, follow these steps:

  1. Run “Command Prompt” with administrator privileges.
  2. Install service using Command: > C:\memcached\memcached.exe -d install
  3. Start “memcached” service from Windows Services or using this command: > C:\memcached\memcached.exe -d start

That is it, now your memcached server is installed and is listening to port 11211. There is one more thing left to do. By default, server is set to 64Mb memory limit, which is too small.

To configure Memcached for memory or port, follow these steps:

  1. go to Registry Editor and find key “HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/memcached  Server”
  2. Change the ImagePath entry to:  ”C:\memcached\memcached.exe” -d runservice -m 512

This way you will use 512 Mb memory limit for your server.

Other options is:

  1. memcached.exe -d uninstall
  2. memcached.exe -d install -m 512

Complete list of options to configure as follows:

  • -p [num] TCP port number to listen on (default: 11211)
  • -U [num] UDP port number to listen on (default: 0, off)
  • -s [file] unix socket path to listen on (disables network support)
  • -a [mask] access mask for unix socket, in octal (default 0700)
  • -l [ip address] interface to listen on, default is INDRR_ANY
  • -d start tell memcached to start
  • -d restart tell running memcached to do a graceful restart
  • -d stop|shutdown tell running memcached to shutdown
  • -d install install memcached service
  • -d uninstall uninstall memcached service
  • -r maximize core file limit
  • -u [username] assume identity of (only when run as root)
  • -m [num]] max memory to use for items in megabytes, default is 64 MB
  • -M return error on memory exhausted (rather than removing items)
  • -c [num] max simultaneous connections, default is 1024
  • -k lock down all paged memory.
  • -v verbose (print errors/warnings while in event loop)
  • -vv very verbose (also print client commands/reponses)
  • -h print this help and exit
  • -i print memcached and libevent license
  • -b run a managed instanced (mnemonic: buckets)
  • -P [file]] save PID in , only used with -d option
  • -f [factor] chunk size growth factor, default 1.25
  • -n [bytes]] minimum space allocated for key+value+flags, default 48

Mar 20 2013

FTP Filezilla – 421 Sorry, cleartext sessions are not accepted on this server.

Kailash Yadav
Some times when  you connect to the webhost server via FileZilla (or any ftp client) you may encounter this error message.
“421 Sorry, cleartext sessions are not accepted on this server.”
To solve this issue you just need to follow below mentioned steps.
Just add a ftpes:// before the domain name
Old Example
host : example.com
username : xxx
pass : yyy
port : 21
host : ftpes://example.com
username : xxx
pass : yyy
port : 21
Hope it gonna help.

Oct 9 2012

Remove query string while redirect in .htaccess

Kailash Yadav

Here is small example where i want to redirect from “url” to “url2″ without any query string.

url1: http://www.example.com/url/getdata.php?p=1&start=30

url2: http://www.example.com/url2/getdata.php

so below rule will help you achieve that.

RewriteRule ^url/(.*)$ /url2/$1? [L,R=301]

Oct 9 2012

Strip HTML tags in SQL Server

Kailash Yadav

While working on one of old site, i came across an issue where i have to remove HTML tags from the full name field of one table column.

So here is small User Defined Function you can use to solve your problem.

SET @Start = CHARINDEX('',@HTMLText,CHARINDEX(' 0 AND @End > 0 AND @Length > 0
SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
SET @Length = (@End - @Start) + 1

May 18 2011

Refresh Magento Cache Programmatically

Kailash Yadav

When writing processes to automate some of Magento’s normally laborious tasks, perhaps for a product-import script, a mass attribute update script, category import, or inventory adjustment, keep in mind that you may have to refresh some kind of cache — especially when working with attributes. If you are encountering quirks or inconsistencies with your data, try these:

  • Rebuild Catalog Index Mage::getSingleton('catalog/index')->rebuild();
  • Rebuild Flat Catalog Product Mage::getResourceModel('catalog/product_flat_indexer')->rebuild();
  • Inventory Stock Mage::getSingleton('cataloginventory/stock_status')->rebuild()

May 16 2011

Regular expression for HTML tags in string

Kailash Yadav

Here is one of most powerful and used regular expression which was used by every developer once in their life for sure.

How to select content or string inside a HTML tag using regular expression in all languages.

I am sharing this regular expression with you. This regular expression is useful when you fetching content from Other Website using cURL.
]*>(.*?)} ?>

Here is one small example:
//Example to get text inside given tag
$content = file_get_contents("http://www.example.com");
$tag= 'h1'; //we will extract page heading

preg_match("{<'.$tag.'[^>]*>(.*?)}", $content, $match);
$data = $match[0];
echo $data;

Note: This only returns text(string or HTML) inside the Tag you have given. It doesn’t include that tag.

May 9 2011

Google Sitemap Generator for WordPress

Kailash Yadav

While submitting my website to different search engine the first requirement is Sitemap.xml. As i was using wordpress to run my website. How to build dynamic sitemap xml i came accross this very fine plugin.


This plugin will generate a special XML sitemap which will help search engines like Google, Bing, Yahoo and Ask.com to better index your blog. With such a sitemap, it’s much easier for the crawlers to see the complete structure of your site and retrieve it more efficiently. The plugin supports all kinds of WordPress generated pages as well as custom URLs. Additionally it notifies all major search engines every time you create a post about the new content.


  • Available for all WordPress versions since 1.5
  • No PHP skills or file changes needed
  • User interface to customize all parameters like priorities etc.
  • Available in many languages
  • Generates automatically a sitemap for all types of WordPress pages
  • Calculates a priority for each post, based on the number of comments
  • Notifies Ask.com, Google, Bing and YAHOO about changes via ping
  • Includes a WordPress filter for other plugins which can add their pages to the sitemap
  • Generates a static XML file as well as a zipped version
  • …and many more!

May 6 2011

PHP Fatal error: Call to a member function toHtml() on a non-object in …/Layout.php on line 529

Kailash Yadav

If you’ve just upgraded your Magento Commerce site to the 1.4.x release from a 1.3.x release or you using old theme on magneto 1.4.x + , and you forgot to change the theme/template to the default one before you performed the upgrade, you’ll probably end up with a blank white screen.

If we look at line 529 of the “Layout.php” file we can see that it’s itterating over several objects ($this->_output) and producing a coalesced output which can then be displayed on the screen.

* Get all blocks marked for output
* @return string
public function getOutput()
$out = '';
if (!empty($this->_output)) {
foreach ($this->_output as $callback) {
$out .= $this->getBlock($callback[0])->$callback[1]();

return $out;

In 1.4.x Magento overhauled the templates and themes code so your 1.3.x template/theme isn’t going to work in a 1.4.x environment without some re-coding.  To get over this particular problem, find and edit the ‘page.xml’ file in your template/theme directory.  It should be in ./app/design/frontend/default/{your_theme}/layout/page.xml

Change the line
<block type=”core/profiler” output=”toHtml”/>

<block type=”core/profiler” output=”toHtml” name=”core_profiler”/>

Clear the cache directory using “rm -rf magento/var/cache/*” or using admin panel configuration > cache management and refresh your page.  All being well your site should spring back in to life.

If this didn’t work for you, or your template/theme directory doesn’t have a local copy of the ‘page.xml’ file, look at the default files and ensure that they were updated when you upgraded Magento.  You’ll find the files in:


Hope this helps.

May 3 2011

Setting a variable in .htaccess

Kailash Yadav

I don’t know how useful it will be for you but still I’m sharing this information with you all.

How to set a variable in .htaccess file which you have to write so many times and it changes when it goes to development and then on production as well.

In my case,

I have a domain http://abc.example.com which needs to be redirected to http://www.xyz.com/

So my Rules are

RewriteRule ^secu/?$ http://www.xyz.com/security/ [L,R=301]
RewriteRule ^secu/archives.php/(.*)$ http://www.xyz.com/security/archive/$1 [L,R=301]

RewriteRule ^cnews/?$ http://www.xyz.com/news/ [L,R=301]
RewriteRule ^cnews/archives.php/(.*)$ http://www.xyz.com/news/archive/$1 [L,R=301]

#Setting Variable for Host Name as per the Development Environment

RewriteCond %{HTTP_HOST} ^abc.example.local.com$ [NC]
RewriteRule .* - [E=host_name:xyz.local.com]

RewriteCond %{HTTP_HOST} ^iabc.example.com$ [NC]
RewriteRule .* - [E=host_name:xyz.com]

RewriteRule ^secu/?$ http://%{ENV:host_name}/security/ [L,R=301]
RewriteRule ^secu/archives.php/(.*)$ http://%{ENV:host_name}/security/archive/$1 [L,R=301]

RewriteRule ^cnews/?$ http://%{ENV:host_name}/news/ [L,R=301]
RewriteRule ^cnews/archives.php/(.*)$ http://%{ENV:host_name}/news/archive/$1 [L,R=301]

As you can see in above example, now you don’t have to worry which environment you are working your rules will always work.

You can also set the variable without any condition and access it directly as mentioned below.

RewriteRule .* - [E=foo:bar]


May 2 2011

Defer Banner Ads or JavaScript To Load After Page Loads

Kailash Yadav

There are many times when you might want a certain banner ad to load only after you page loads fully, however, not everyone is an expert in AJAX or JavaScript for that matter to make change code and make the code efficient.

If you are a webmaster and have been worried about slow page load times, there is a easier way to defer certain banners or JavaScript code to load after the browser has rendered the rest of the page. This trick can be used for both inline and external JavaScript by using the “defer” attribute specified in HTML 4.01 and later.

To defer banner ads or any JavaScript code to load after the entire page has rendered, just add the attribute defer=”defer” to the script tag and the browser will ignore the code within the script and load it after it has finished loading the rest of the content.

Here are some examples of using the defer attribute with a script:

//inline JS example
//external JS example

Using this trick will ensure that your non JavaScript content loads quickly enough so that it does not hinder a user’s browsing experience. However, it may not improve the overall page load times since the browser will continue to load the deferred JavaScript content after the rest of the page has loaded.