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