Friday, April 12, 2013

Output Caching in IIS, KernelCachePolicy

This is PHP file to print date time

<?php
 print date('D, d M Y H:i:s T');
?>
Browser to: http://localhost/date.php ---------------------------------------------------------------------------------- you see that page is cached after 3 calls, if you setup cache rules in web.config CACHING INTRICACIES Even if you enable Output Caching, IIS does not immediately cache a request. It must be requested a few times before IIS considers a request to be "cache worthy". Cache worthiness can be configured via the ServerRuntime section described in this MSDN article. http://msdn.microsoft.com/en-us/library/ms690574 By default, when you create a cache rule a page is cached when it is requested 2 times within a 10 second time period. You can change these default values by first making a change to your applicationHost.config file and then updating your web.config file. Your applicationHost.config file is typically in the c:\Windows\System32\inetsrv\config directory and is most easily opened with Notepad from a command prompt with administrator privileges. In that file, find the following entry (a child of the element):
. Change Deny to Allow and save the file.
<sectionGroup name="system.webServer">
    <section name="serverRuntime" overrideModeDefault="Allow" />
 </sectionGroup>
---------------------------------------------------------------------------------- Then in web.config Refrence <configuration> <system.webServer> <serverRuntime frequentHitThreshold="3" frequentHitTimePeriod="00:00:20" /> <caching> <profiles> <add extension=".php" policy="DontCache" kernelCachePolicy="CacheForTimePeriod" duration="00:05:30" /> </profiles> </caching> </system.webServer> </configuration>
and finally to view the files in cache following command should be run netsh http show cachestate Refrence

Deleting duplicate and repetitive posts from wordpress using Mysql

Repetitive post are the post which have same post title

DELETE bad_rows.*
from wp_posts as bad_rows
inner join (
select post_title, MIN(id) as min_id
from wp_posts
group by post_title
having count(*) > 1
) as good_rows on good_rows.post_title = bad_rows.post_title
and good_rows.min_id <> bad_rows.id;

Tuesday, April 9, 2013

How to create dynamic tasks in C#


Task[] tasks = new Task[1000];
 
for (int i = 0i < 1000i++)
{
tasks[i= Task.Factory.StartNew(() =>
{
Console.WriteLine(System.DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt"));
});
}
Task.WaitAll(tasks);

Sending and recieving message using C# in Windows Message Queue

From Control panel -> Turn windows features on or off its possible to install windows Message Queuing
http://technet.microsoft.com/en-us/library/cc730960.aspx

To Send and recieve message using c# first you have to create a message queue:
http://www.codeproject.com/Articles/5830/Using-MSMQ-from-C

if(MessageQueue.Exists(@".\Private$\MyQueue"))
//creates an instance MessageQueue, which points
//to the already existing MyQueue
mq = new System.Messaging.MessageQueue(@".\Private$\MyQueue");
else
//creates a new private queue called MyQueue
mq = MessageQueue.Create(@".\Private$\MyQueue");


To Send message

System.Messaging.Message mm = new System.Messaging.Message();
mm.Body = txtMsg.Text;
mm.Label = "Msg" + j.ToString();
mq.Send(mm);


and to recieve message

try
{
mes = mq.Receive(new TimeSpan(0, 0, 3));
mes.Formatter = new XmlMessageFormatter(
new String[] {"System.String,mscorlib"});
m = mes.Body.ToString();
}
catch
{
m = "No Message";
}
MsgBox.Items.Add(m.ToString())


to See messages in windows open Computer Management and from Service applications -> Message Queuing