4

Windows に pThreads をインストールする方法を教えてもらえますか。

実際、私は PHP で Threads を有効にしたいと考えています。

require_once( 'Thread.php' );

// test to see if threading is available
if( ! Thread::available() ) {
die( 'Threads not supported' );
}

// function to be ran on separate threads
function paralel( $_limit, $_name ) {
for ( $index = 0; $index < $_limit; $index++ ) {
    echo 'Now running thread ' . $_name . PHP_EOL;
    sleep( 1 );
}
}

// create 2 thread objects
$t1 = new Thread( 'paralel' );
$t2 = new Thread( 'paralel' );

 // start them
$t1->start( 10, 't1' );
$t2->start( 10, 't2' );

// keep the program running until the threads finish
while( $t1->isAlive() && $t2->isAlive() ) {

}

エラー表示は「スレッドはサポートされていません」です。

私の PHP バージョン 5.3.4 。

4

2 に答える 2

4
于 2013-11-18T21:42:44.180 に答える
1

投稿したコードは pthreads と互換性がありません。

pthreads の Windows バイナリが利用可能http://windows.php.net/downloads/pecl/releases/pthreads/

リリースをダウンロードし、拡張 dll (php_pthreads.dll) を拡張ディレクトリに展開し、ランタイム dll (pthreadVC2.dll) を php ディレクトリ (php.exe と同じディレクトリ) に展開し、構成に extension=php_pthreads.dll を追加するだけです。

pthreads コードの例は、github http://github.com/krakjoe/pthreadsにあります。

于 2013-06-06T06:24:11.587 に答える