watch "echo stats|nc 127.0.0.1 11211"

A Linux blog by ioMeWeekly, includes tutorials, news, help, programming, tips and how-to guides for opensource applications.
watch "echo stats|nc 127.0.0.1 11211"
<?php $memcache_host="127.0.0.1"; $memcache_port="11211"; $memcache = new Memcache; $memcache->connect($memcache_host,$memcache_port) or die ("Cannot connect"); $return=($memcache->getStats()); foreach ($return as $key => $value) { echo $key." : ".$value."<br>"; } ?>
<?php require('connect_db.php'); $memcache_host="127.0.0.1"; $memcache_port="11211"; $memcache = new Memcache; $memcache->connect($memcache_host,$memcache_port) or die ("Cannot connect"); $version = $memcache->getVersion(); echo "Version: ".$version; $query="select * from exampleDB limit 1;"; $key = md5($query); $get_result = $memcache->get($key); if ($get_result) { print_r($get_result); echo "Data retrieved from memcache"; } else { $result = mysql_query($query); if (!$result) { die('Invalid query: ' . mysql_error()) } $row = mysql_fetch_array($result); print_r($row); $memcache->set($key, $row, MEMCACHE_COMPRESSED, 10); echo "Data retrieved from database"; } ?>
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6-8.noarch.rpmWhat is IUS? The IUS Community Project is an effort to package rpms of the latest stable versions of the most commonly requested software on Red Hat Enterprise Linux and CentOS. IUS provides a better way to upgrade PHP/MySQL/Python/Etc on RHEL or CentOS. The project is run by professional Linux Engineers that are primarily focused on RPM Development in the web hosting industry. Download repository rpm from website:
wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-11.ius.el6.noarch.rpm
rpm -Uvh ius-release-1.0-11.ius.el6.noarch.rpm
yum search memcached yum install memcached php-pear chkconfig memcached on service memcached start
pecl search memcache
yum install php-devel gcc zlib zlib-develTo install php extension:
pecl install memcache
vi /etc/php.iniInsert below line to php.ini:
extension=memcache.so
vi /var/www/html/memcache.php
<?php $memcache = new Memcache; $memcache->;connect('127.0.0.1', 11211) or die ("Cannot connect"); $version = $memcache->getVersion(); echo "Version: ".$version."
\n"; $tmp_object = new stdClass; $tmp_object->test1 = 'value1'; $tmp_object->test2 = 472; $memcache->set('key', $tmp_object, false, 20) or die ("Cannot save data"); echo "Stored data in the memcache for 20 seconds
\n"; $get_result = $memcache->get('key'); echo "Data from the cache:
\n"; var_dump($get_result); ?>
wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://www.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
md5sum MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm md5sum MySQL-server-5.6.10-1.el6.x86_64.rpm md5sum MySQL-shared-5.6.10-1.el6.x86_64.rpm md5sum MySQL-client-5.6.10-1.el6.x86_64.rpm
rpm -Uvh MySQL-shared-compat-5.6.10-1.el6.x86_64.rpm rpm -ivh MySQL-shared-5.6.10-1.el6.x86_64.rpm rpm -ivh MySQL-server-5.6.10-1.el6.x86_64.rpm rpm -ivh MySQL-client-5.6.10-1.el6.x86_64.rpm
chkconfig mysql on
service mysql start
cat /root/.mysql_secret
mysqladmin -uroot -p passwordLogin to the newly installed server using its client:
mysql -uroot -pThese are the steps to install latest mysql on CENTOS. Cheers!
<?php //-----Start Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $top = $time; //-----Start Timer-------------------------------------------------// for($j=0;$j<1000;$j++) { $link = mysql_connect($host,$user,$password) or die('Error in Server information'); mysql_select_db($db,$link) or die('Can not Select Databasse'); $query="select * from com_list where field1='value1';"; $res = mysql_query($query); //1 is ok if (!$res) { die('Invalid query: ' . mysql_error()); } while($row = mysql_fetch_array($res)){ $i++; } mysql_free_result($res); mysql_close($link); } echo "Total lines :".$i; //-----End Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $bottom = $time; //-----End Timer-------------------------------------------------// $loadtime = ($bottom-$top); echo ("<br> <br>This page generated in $loadtime seconds"); ?>Second script, test_mysqli.php
<?php //-----Start Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $top = $time; //-----Start Timer-------------------------------------------------// for($j=0;$j<1000;$j++) { $link = mysqli_connect($host,$user,$password,$db) or die('Error in Server information'); $query="select * from com_list where field1='value1';"; $res = mysqli_query($link,$query); //1 is ok if (!$res) { die('Invalid query: ' . mysql_error()); } while($row = mysqli_fetch_array($res)){ $i++; } mysqli_free_result($res); mysqli_close($link); } echo "Total lines :".$i; //-----End Timer-------------------------------------------------// $time = microtime(); $time = explode(" ", $time); $time = $time[1] + $time[0]; $bottom = $time; //-----End Timer-------------------------------------------------// $loadtime = ($bottom-$top); echo ("<br> <br>This page generated in $loadtime seconds"); ?>