2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【PHP】pthreadsでマルチスレッド

Last updated at Posted at 2016-07-03

##インストール(Windows)

参考:インストール手順

1.phpinfo()で「PHP Extension Build」でVCを確認する。

※VCはコンパイルしたソフトのバージョン
VC6:Visual Studio 6
VC9:Visual Studio 2008
VC10:Visual Studio 2010
VC11:Visual Studio 2012
VC12:Visual Studio 2013
参考:php関連でのvc9とvc11の違い

※TSはThread Safe=マルチスレッド対応。NTSはNon Thread Safe=スレッド非対応。
参考:PHP のNon Thread Safe とThread Safe の違い

2.該当するバイナリをDLする。

ダウンロード先:http://windows.php.net/downloads/pecl/releases/pthreads/

※バージョン3.0以上はPHP7対応
※PHP5.6.19をいれていたが、バージョンが古いと以下のエラー。バージョン2.0.9で動いた。

PHP Warning:  PHP Startup: pthreads: Unable to initialize module
Module compiled with module API=20121212
PHP    compiled with module API=20131226
These options need to match
 in Unknown on line 0

3.DLしたzipを展開して、各ディレクトリへ移動。
①php_pthreads.dll
→エクステンションディレクトリへ
例)C:\xampp\php\ext

②pthreadVC2.dll
→php.exeと同じディレクトリへ
例)C:\xampp\php

4.php.iniに追加
※場所はどこでもOK
extension=php_pthreads.dll

##書き方

<?php
 class TestThread extends Thread{
    /**
    * @Overide
    * startしたときに呼ばれる
    */
    public function run(){

    }
}

$testThread1 = new TestThread();
$testThread1->start();
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?