2016-11-12 1 views

答えて

1

$_SERVERはスーパーグローバルであり、新しいスレッドを作成するときにグローバルはpthreadsによってコピーされません。

<?php 
class ServerAwareThread extends Thread { 

    public function __construct(array $server) { 
     $this->server = (array) $server; 
    } 

    public function run() { 
     $_SERVER = array_merge(
      $_SERVER ?: [], $this->server); 

     /* show that it's super global */ 
     $this->other(); 
    } 

    public function other() { 
     var_dump($_SERVER); 
    } 
} 

$thread = new ServerAwareThread($_SERVER); 

$thread->start() && $thread->join(); 
?> 

は、単に新しいスレッドでの依存関係とセットアップ$_SERVERとして$_SERVERに渡します。

関連する問題