Sunday, 21 July 2013

PHP Multithreading Example and php_pthreads Configurataion

If Php Support Multithreading means you must configure following things

1. Download Php with Thread Safe from http://windows.php.net/download/

2. After Php installation, download pthreads libraries from http://windows.php.net/downloads/pecl/releases/pthreads/

3. After download and extraction , copy php_pthreads.dll and pthreadVC2.dll this files.

4. Then goto your Php\ext directory and paste it.

5. Then  goto your PHP directory and find and rename "php.ini-development" file to "php.ini".

6. Open php.ini file in Notepad and find ;extension=php_shmop.dll line and add extension=php_pthreads.dll after that line.

7. Then Find ;extension_dir = "ext" line and remove ; from that line.

8. Finaly Save that php.ini file

9. Done

Then Run Below Multithreading Example.


PHP Multithreading Example

<?php
class MultiThread_EX extends Thread
{
    public function __construct($arg)
    {
        $this->arg = $arg;
    }

    public function run()
    {
        if($this->arg){
            printf("Hello %s\n", $this->arg);
        }
    }
}

$thread = new MultiThread_Ex("World");
if($thread->start())
$thread->join();




Kindly Bookmark and Share it:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...