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 전달합니다.

관련 문제