PurabTech is technical blog for Programmer and Coders
Author: Purab
I am Purab from India, Software development is my profession and teaching is my passion.
Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks.
Purab's Github Repo
Youtube Chanel Video Tutorials
Connect to on LinkedIn
As a developers need to check the mysql logs. Many times for any request how many mysql queries are running or executed we need to know.
How to create mysql logs for specific queries.
How to create mysql logs for specific queries
In this tutorial I will show you how to created mysql log file for checking the SELECT, UPDATE, DELETE or any types of mysql queries.
If you are using the linux then use the my.cnf file which will be located in etc folder. If you are using the windows then use the my.ini file. That file you will find in following location in case of wamp server.
c:\wamp\bin\mysql\mysql5.0.45\my.ini
I am using the Linux so here I am giving that example. use following command.
Today when I logged to my wordpress blog account and looked at dashboard, I saw the new changed statistic graph.
The new statistic graph is looking really very cool. New graph version is better for those who are visually improved so nicely.
WordPress changed the statistic graph
For wordpress blogger and website users this news is really great.
Seeing this graph I must say you will miss having the grand total of both syndicated and on-site views for an entry.
As we know we need to updgrade the “WordPress.com Stats” wordpress plugin to see the updated stats in your hosted wordpress blogs.
You can download or update the wordpress stat plugin using following URL
http://wordpress.org/extend/plugins/stats/
WordPress changed the statistic graph
What wordpress is saying about changed Stat in Twitter.
Sexy Stats: http://wp.me/pf2B5-1n9
As per wordpress:
Each module can be opened and closed, moved, or hidden completely. If you don’t want to see a module, minimize it with one click or use the Screen Options to keep it out of sight. Customize everything and view stats the way you want to.
As you hover over each bar in the chart it changes color and displays a tooltip, giving you more information about the data. If the chart is showing data by day, Saturdays and Sundays have a light gray background to make it easier to see weekly patterns. Under the chart you’ll notice a new area, called “fortune cookies,” where we’ll highlight key stats.
During the redesign we went with bar charts because the end of one day and the beginning of another shouldn’t be connected. Each day starts at zero and we think bar charts work much better for this type of data. We hope you’ll agree once you get used to the change.
In this first phase of the stats redesign we’ve focused on the main page. This will allow us to collect feedback from you so we can tweak everything as we go. We’ve only mentioned a few of the highlights here, so take your stats for a drive around town to get used to the feel. Let us know what you like and what you might change. As we gather feedback we’ll apply a bit of sexy to the other stat pages.
Few time ago wordpress just announced the partnership with Microsoft. Microsoft is saying “WordPress as the new default blogging platform on Windows Live Spaces!” WordPress as the new default blogging platform on Windows Live Spaces!”
Windows or MSN Space is migrating to wordpress.com
Windows or MSN Space is migrating to wordpress.com
Microsoft is saying “Over the last few weeks, we’ve spent a good bit of time talking about our approach to partnering with the web, and as part of that, how we’re deeply integrating with the leading consumer services that you find most valuable. Earlier today, I had the opportunity to get on stage at TechCrunch Disrupt, and with Toni Schneider, CEO of Automattic (the parent company of WordPress.com), announce an exciting partnership between our companies.”
Using this step more than 30 million users of windows space will migrate to wordpress.com.
As we looked at how we brought Windows Live and WordPress.com together, there were three big things we wanted to deliver:
Giving existing Windows Live Spaces customers an easy upgrade of their blogging experience to WordPress.com
Letting anyone connect their WordPress.com blog to Messenger so their Messenger friends are updated when they publish a new post on WordPress.com
Allowing Windows Live customers to easily create new blogs on WordPress.com
Windows or MSN Space is migrating to wordpress.com
For detail information for windows space user can use the following article for checking this further information about migrating the blog to wordpress.com
We all know who is Matthew Charles Mullenweg is. He dont need any introduction. Many times users, clients and developers are very interested to see what Matt is saying about wordpress and technology.
Videos of Matt Mullenweg – WordPress founder
In this article I am going to give you some videos of Matt which published in 2010.
Matt Mullenweg says Hi to Me!
wordcamp 2010 jerusalem q&a with Matt Mullenweg
Matt Mullenweg keynote – WordCamp Houston
Matt Mullenweg at WordCamp Houston
Matt Mullenweg and Mike Little : Cardiff July 2009.
Matt Mullenweg says hello to WordCamp Malaysia 2010 Part 1
You Are the Pride: Matt Mullenweg
WordPress creator Matt Mullenweg discusses his early days as a student at the University of Houston, and his passion for helping people find their …
WordPress Founder Matt Mullenweg
An interview with Matt Mullenweg, conducted at WordCamp SF 2010.
Matt Mullenweg talks about “Twenty Ten” for WordPress 3.0
An excerpt from Matt’s state of the word address on WordCamp San Francisco 2010
When you are running any script on server or running any application you want to know how much memory or disk uses is happened by application.
how to find out cpu and disk usage in linux
how to find out cpu and disk usage in linux
When you are doing load testing this time this kind of applications are very useful to check the server status. Create file name CPU-Disk.sh and put following content in that.
#!/bin/sh
# Change this as needed
OUTPUT_FILE=file.txt
# Initially delete old output file if needed.
/bin/rm -f $OUTPUT_FILE
while [ 1 -eq 1 ]; do
date >> $OUTPUT_FILE
echo "------------------------" >> $OUTPUT_FILE
cat /proc/meminfo >> $OUTPUT_FILE
echo "------------------------" >> $OUTPUT_FILE
df -k >> $OUTPUT_FILE
echo "------------------------" >> $OUTPUT_FILE
top -b -i -n 1 >> $OUTPUT_FILE
# Record terminator. Add more === if needed :)
echo "========================" >> $OUTPUT_FILE
sleep 60
done
This command is useful to create the sh file executable in linux
#chmod +x /YOURPATH/CPU-Disk.sh
when you need to check the server status you need to run the this file using this command
You can use the windows machine from linux OS. Using rdesktop program this is possible. Here is Linux tutorial, how to use rdesktop command in linux. Windows and Linux have made inroads into organizations around the world.
how to use rdesktop command in linux
how to use rdesktop command in linux
Rdesktop is a Linux implementation of Remote Display Protocol (RDP). Windows uses RDP to connect to other Windows computers via Terminal Services. With rdesktop, you can open a remote control session on a Windows NT/2000/XP machine from a Linux box.
On fedora OS rdesktop utility is already installed. If that utility is not installed then use following command to install rdesktop
#yum install rdesktop
Use following command to use the remote desktop
[siwan@siwank-pc ~]$ rdesktop 192.168.2.45
For Full screen Use following Command.
[siwan@siwank-pc ~]$ rdesktop -f 192.168.2.45
How to minumize the rdesktop?
Use the following command. If you are in full screen mode then press ctrl + alt + enter button to back again.
This is very nice utility for Linux and Windows users. Who need to work on both the OS on same time.
Many times we need the fadein and fadeout effect using javascript. Javascript tutorial for, Fadein and Fadeout effect through javascript example. But many developers go for jquery for using simple fadein and fadeout effect
Fadein and Fadeout effect through javascript example
Fadein and Fadeout effect through javascript example
I suggest not to Jquery and Use following code for effect. This is very minimal code and you can very easily customize the CSS and javascript as per your requirement.
<html>
<head>
<style type="text/css">
.popup {
border: solid 1px #333;
font-family: Tahoma;
font-size: 12px;
display: none;
position: absolute;
width: 300px;
z-index: 60;
}
.popuptitle {
background: blue;
color: white;
font-weight: bold;
height: 15px;
padding: 5px;
}
.popupbody {
background: #ddd;
padding: 5px;
text-align: center;
}
#popup1 { top: 100px; left: 50px; }
#popup2 { top: 100px; left: 400px; }
</style>
<script type="text/javascript">
var fadeOpacity = new Array();
var fadeTimer = new Array();
var fadeInterval = 100; // milliseconds
function fade(o,d)
{
// o - Object to fade in or out.
// d - Display, true = fade in, false = fade out
var obj = document.getElementById(o);
if((fadeTimer[o])||(d&&obj.style.display!='block')||(!d&&obj.style.display=='block'))
{
if(fadeTimer[o])
clearInterval(fadeTimer[o]);
else
if(d) fadeOpacity[o] = 0;
else fadeOpacity[o] = 9;
obj.style.opacity = "."+fadeOpacity[o].toString();
obj.style.filter = "alpha(opacity="+fadeOpacity[o].toString()+"0)";
if(d)
{
obj.style.display = 'block';
fadeTimer[o] = setInterval('fadeAnimation("'+o+'",1);',fadeInterval);
}
else
fadeTimer[o] = setInterval('fadeAnimation("'+o+'",-1);',fadeInterval);
}
}
function fadeAnimation(o,i)
{
// o - o - Object to fade in or out.
// i - increment, 1 = Fade In
var obj = document.getElementById(o);
fadeOpacity[o] += i;
obj.style.opacity = "."+fadeOpacity[o].toString();
obj.style.filter = "alpha(opacity="+fadeOpacity[o].toString()+"0)";
if((fadeOpacity[o]=='9')|(fadeOpacity[o]=='0'))
{
if(fadeOpacity[o]=='0')
obj.style.display = 'none';
else
{
obj.style.opacity = "1";
obj.style.filter = "alpha(opacity=100)";
}
clearInterval(fadeTimer[o]);
delete(fadeTimer[o]);
delete(fadeTimer[o]);
delete(fadeOpacity[o]);
}
}
</script>
</head>
<body>
popup1',true);"/>
popup2',true);"/>
popup1"></pre>
<div>Fade Popup 1</div>
<pre>
<div>
<p>Press close to fade out this Popup</p>
<input type="button" value="Close" onClick="fade('popup1',false);"/>
</div>
</div>
popup2"></pre>
<div>Fade Popup 2</div>
<pre>
<div>
<p>Press close to fade out this Popup</p>
<input type="button" value="Close" onClick="fade('popup2',false);"/>
</div>
</div>
</body>
</html>
If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.
The MongoDB server is built to already work with your current web server. The problem is that you’ll need to install drivers for your preferred backend language – PHP, Ruby, Node.js, Perl, whatever.
How to use mongodb with php
How to use mongodb with php
For installing the Mongo use following URL:
If you dont have pecl installed on your linux machine then use following command.
# yum install php-pecl*
then use following command
# pecl install mongo
Then open the php.ini file. if you are using the linux then use following command.
# vim /etc/php.ini
## Add following lines, end of php.ini file ##
# MongoDB Driver
extension=mongo.so
Restart the apache webserver using following command
# /etc/init.d/httpd restart
If Mongodb server is running then use can test your mongodb database using following code:
Create the mongotest.php file
<!--?php
// connect
$m = new Mongo();
// select a database
$db = $m--->wordpress;
$collection = $db->wordpressapi;
// add an element
$obj = array( "title" => "Sony this Good.\n", "author" => "Wordpressapi.com" );
$collection->insert($obj);
// add another element, with a different "shape"
$obj = array( "title" => "Wordpressapi.com", "online" => true );
$collection->insert($obj);
// find everything in the collection
$cursor = $collection->find();
// iterate through the results
foreach ($cursor as $obj) {
echo $obj["title"] . "\n";
echo $obj["author"] . "\n";
}
// disconnect
$m->close();
?>
If you open this file in browser then you can see the following words in browser:
Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com
If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.
For installing the Mongo use following URL:
If you dont have pecl installed on your linux machine then use following command.# yum install php-pecl*
then use following command# pecl install mongo
Then open the php.ini file. if you are using the linux then use following command.
# vim /etc/php.ini
## Add following lines, end of php.ini file ### MongoDB Driverextension=mongo.so
Restart the apache webserver using following command
# /etc/init.d/httpd restart
If Mongodb server is running then use can test your mongodb database using following code:
Create the mongotest.php file
<!--?php
// connect$m = new Mongo();
// select a database$db = $m--->wordpress;$collection = $db->wordpressapi;
// add an element$obj = array( "title" => "Sony this Good.\n", "author" => "Wordpressapi.com" );$collection->insert($obj);
// add another element, with a different "shape"$obj = array( "title" => "Wordpressapi.com", "online" => true );$collection->insert($obj);
// find everything in the collection$cursor = $collection->find();
// iterate through the resultsforeach ($cursor as $obj) { echo $obj["title"] . "\n"; echo $obj["author"] . "\n";}
// disconnect$m->close();
?>
If you open this file in browser then you can see the following words in browser:Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com
Mongodb is used for many projects now, it is quite fast. I given full detailed information about How to install Mongodb on linux box. Before installing the Mongodb on linux box you need to install following packages on box.
[root@sonyk-pc mongodb-linux-i686-1.6.2]# ./bin/mongod
./bin/mongod --help for help and startup options
Thu Sep 9 13:10:55 MongoDB starting : pid=22159 port=27017 dbpath=/data/db/ 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Sep 9 13:10:55 db version v1.6.2, pdfile version 4.5
If you want to create mongodb service in linux then use following steps:
create the File: /opt/bin/mongodb-stop
Put following code in that file:
#!/bin/bash
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;
if [ "${pid}" != "" ]; then
kill -2 ${pid};
fi
create the File: /opt/bin/mongodb-start
Put following code in that file:
#!/bin/sh
/opt/mongodb/bin/mongod --config /opt/config/mongodb \
## --upgrade \ ##runs a database upgrade option if needed \
File: /opt/config/mongodb
Put following code in that file:
# Configuration Options for MongoDB
#
# For More Information, Consider:
# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters
# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration
dbpath = /srv/db/mongodb
logpath = /srv/db/mongodb.log
logappend = true
bind_ip = 127.0.0.1
port = 27017
fork = true
auth = true
# noauth = true
Do that file as linux executable
chmod +x /opt/bin/mongodb-start
chmod +x /opt/bin/mongodb-stop
We’ve also created a very basic “init script” as a wrapper around the mongodb-start and mongo-stop scripts described above. You will still need to modify and manage the configuration of your MongoDB server in the files above. This script only provides a means for ensuring that MongoDB will start at boot. Issue the following commands:
wget http://library.linode.com/databases/mongodb/reference/init-rpm.sh
mv init-rpm.sh /etc/rc.d/init.d/mongodb
chmod +x /etc/rc.d/init.d/mongodb /etc/init.d/mongodb
chkconfig –add mongodb
chkconfig –level 35 mongodb on
You will also need to create a user and group for mongodb; issue the following command:
useradd -M -r --home-dir /opt/mongodb mongodb
Now issue the following command to ensure that the MongoDB user you just created will have access to all required files in the /srv/db/ hierarchy:
chown mongodb:mongodb -R /srv/db/
To start and stop MongoDB using the init script, issue the appropriate command from the following:
/etc/init.d/mongodb start
/etc/init.d/mongodb stop
For checking the web admin interface of Mongodb – listening on port 28017
Check this URL : http://localhost:28017/
Before installing the Mongodb on linux box you need to install following packages on box.[root@sonyk-pc Download]# sudo yum -y install git tcsh scons gcc-c++ glibc-devel[root@sonyk-pc Download]# sudo yum -y install boost-devel pcre-devel js-devel readline-devel[root@sonyk-pc Download]# sudo yum -y install boost-devel-static readline-static ncurses-static
For 32bit user use following command[root@sonyk-pc Download]# wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.6.2.tgz
For 64bit use following command[root@sonyk-pc Download]# wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.6.2.tgz
[root@sonyk-pc Download]# tar xzf mongodb-linux-i686-1.6.2.tgz [root@sonyk-pc Download]# cd mongodb-linux-i686-1.6.2
Mongo stores database in data/db folder. so we need to create those folder using following command.
[root@sonyk-pc mongodb-linux-i686-1.6.2]# sudo mkdir -p /data/db/[root@sonyk-pc mongodb-linux-i686-1.6.2]# sudo chown `id -u` /data/db
Using following command you can start the mongo database.
[root@sonyk-pc mongodb-linux-i686-1.6.2]# ./bin/mongod./bin/mongod –help for help and startup optionsThu Sep 9 13:10:55 MongoDB starting : pid=22159 port=27017 dbpath=/data/db/ 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Thu Sep 9 13:10:55 db version v1.6.2, pdfile version 4.5
If you want to create mongodb service in linux then use following steps:
[root@sonyk-pc Download]# wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.6.2.tgz [root@sonyk-pc Download]# tar xzf http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.6.2.tgz[root@sonyk-pc Download]# mv mongodb-linux-i686-1.6.2 /opt/mongodb[root@sonyk-pc Download]# mkdir -p /srv/db/mongodb[root@sonyk-pc Download]# touch /srv/db/mongodb.log
[root@sonyk-pc Download]# mkdir /opt/bin/[root@sonyk-pc Download]# mkdir /opt/config/
create the File: /opt/bin/mongodb-stopPut following code in that file;
create the File: /opt/bin/mongodb-startPut following code in that file:
#!/bin/sh
/opt/mongodb/bin/mongod --config /opt/config/mongodb \## --upgrade \ ##runs a database upgrade option if needed \
File: /opt/config/mongodbPut following code in that file:
# Configuration Options for MongoDB## For More Information, Consider:# - Configuration Parameters: http://www.mongodb.org/display/DOCS/Command+Line+Parameters# - File Based Configuration: http://www.mongodb.org/display/DOCS/File+Based+Configuration
dbpath = /srv/db/mongodblogpath = /srv/db/mongodb.loglogappend = true
bind_ip = 127.0.0.1port = 27017fork = true
auth = true# noauth = true
Do that file as linux executatblechmod +x /opt/bin/mongodb-startchmod +x /opt/bin/mongodb-stop
We’ve also created a very basic “init script” as a wrapper around the mongodb-start and mongo-stop scripts described above. You will still need to modify and manage the configuration of your MongoDB server in the files above. This script only provides a means for ensuring that MongoDB will start at boot. Issue the following commands:
wget http://library.linode.com/databases/mongodb/reference/init-rpm.shmv init-rpm.sh /etc/rc.d/init.d/mongodbchmod +x /etc/rc.d/init.d/mongodb /etc/init.d/mongodbchkconfig –add mongodbchkconfig –level 35 mongodb on
You will also need to create a user and group for mongodb; issue the following command:
useradd -M -r --home-dir /opt/mongodb mongodb
Now issue the following command to ensure that the MongoDB user you just created will have access to all required files in the /srv/db/ hierarchy:
chown mongodb:mongodb -R /srv/db/
To start and stop MongoDB using the init script, issue the appropriate command from the following:
/etc/init.d/mongodb start/etc/init.d/mongodb stop
For checking the web admin interface of Mongodb – listening on port 28017Check this URL : http://localhost:28017/
PHP tutorial for, Post message to another server through fopen and fsockopen in php. When this comes to sending data to server to server we need to post the data using web services.
Many people want to use the curl php method but there are serious issues with that.
Post message to another server through fopen and fsockopen in php
Post message to another server through fopen and fsockopen in php
So I recommended to use fopen function to post the message to server to server.
You can use the following code for post the message to another server using fopen and fsockopen
function post($host, $post_url,$port,$data) {
$errno = 0;
$errstr = '';
$path = str_replace($host,'',$post_url); // IP of minor instance
$header_variables = "POST / HTTP/1.1\r\n";
$header_variables .= "Host: $host\r\n";
$header_variables .= "Connection: Close\r\n";
$header_variables .= "Content-Type: application/xml\r\n";
$header_variables .= "Content-Length: " . strlen($data) . "\r\n\r\n";
// establish the connection and send the request
$fp = fsockopen($host, $port, &$errno, &$errstr, 15);
if ($fp) {
stream_set_timeout($fp, 15);
fputs($fp, $header_variables);
fputs ($fp, $data); //data written
fputs ($fp, "\r\n"); //request posted
$response = stream_get_contents($fp);
$info = stream_get_meta_data($fp);
if (!$info['timed_out'] && $fp) {
//get response and everything is ok
} else {
trigger_error('Timed out for '.$post_url);
exit();
}
fclose($fp); //close the file
} else {
trigger_error('Failed to open socket connection. ');
exit();
}
}
using CURL function post message also possible for that you can use following code
<!--?php
/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/
$ch = curl_init();
$data = array('name' =--> 'Foo', 'file' => '@/home/user/test.png');
curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_exec($ch);
?>