Home > Backend Development > PHP Tutorial > PHP installation threads multi-threaded extension basic tutorial, threads multi-threading_PHP tutorial

PHP installation threads multi-threaded extension basic tutorial, threads multi-threading_PHP tutorial

WBOY
Release: 2016-07-12 09:04:43
Original
880 people have browsed it

Basic tutorial on installing threads multi-thread extension in PHP, threads multi-thread

1. Download pthreads extension

Download address: http://windows.php.net/downloads/pecl/releases/pthreads

2. Determine whether PHP is ts or nts version

Check the Thread Safety item through phpinfo();. This item is to check whether it is thread safe. If it is: enabled, generally it should be the ts version, otherwise it is the nts version.

3. Select the version corresponding to pthreads according to the PHP tsnts version

My php version is 5.4.17, so download the php_pthreads-0.1.0-5.4-ts-vc9-x86.zip file package, where 0.1.0 represents the current pthreads version number, 5.4 is the php version number, and ts is Previously, it was determined that php corresponds to the ts and nts versions. vs9 represents the Visual Studio 2008 compiler, and the final x86 represents the 32-bit version.

4. Download pthreads extension

Download address: http://windows.php.net/downloads/pecl/releases/pthreads

5. Install pthreads extension

Copy php_pthreads.dll to the directory binphpext.
Copy pthreadVC2.dll to the directory binphp.
Copy pthreadVC2.dll to the directory C:windowssystem32.
Open the php configuration file php.ini. Add extension=php_pthreads.dll
at the end hint! Windows systems need to add the path of pthreadVC2.dll to the PATH environment variable. My Computer--->right mouse button--->Properties--->Advanced--->Environment Variables--->System Variables--->Find the path named Path---> ;Edit--->Add the full path of pthreadVC2.dll at the end of the variable value (mine is C:WINDOWSsystem32pthreadVC2.dll).

6. Add thread class

<&#63;php
class Thread
{
  var $hooks = array();
  var $args = array();
  function thread()
  {
  }
  function addthread($func)
  {
    $args = array_slice(func_get_args(), 1);
    $this->hooks[] = $func;
    $this->args[] = $args;
    return true;
  }
  function runthread()
  {
    if(isset($_GET['flag']))
    {
      $flag = intval($_GET['flag']);
    }
    if($flag || $flag === 0)
    {
      call_user_func_array($this->hooks[$flag], $this->args[$flag]);
    }
    else
    {
      for($i = 0, $size = count($this->hooks); $i < $size; $i++)
      {
        $fp=fsockopen($_SERVER['HTTP_HOST'],$_SERVER['SERVER_PORT']);
        if($fp)
        {
          $out = "GET {$_SERVER['PHP_SELF']}&#63;flag=$i HTTP/1.1rn";
          $out .= "Host: {$_SERVER['HTTP_HOST']}rn";
          $out .= "Connection: Closernrn";
          fputs($fp,$out);
          fclose($fp);
        }
      }
    }
  }
}
Copy after login

7. Test pthreads extension

include('thread.php');
class AsyncOperation extends Thread {
  public function __construct($arg){
    $this->arg = $arg;
  }
  public function run(){
    if($this->arg){
      printf("Hello %s\n", $this->arg);
    }
  }
}
$thread = new AsyncOperation("World");
if($thread->start())
  $thread->join();
Copy after login

The above content introduces you to the basic tutorial on installing threads multi-thread extension in PHP. I hope you like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1072548.htmlTechArticlePHP installation threads multi-thread extension basic tutorial, threads multi-threading 1. Download pthreads extension download address: http:// windows.php.net/downloads/pecl/releases/pthreads 2. Determine whether PHP is t...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template