-1
我想在使用pthreads
在php
中创建的线程中使用TCPDF
。
当我使用TCPDF
出现此错误:在使用pthreads创建的线程中使用TCPDF
“通知:未定义的变量:_ SERVER中......”
如何,我必须解决这个问题?
我想在使用pthreads
在php
中创建的线程中使用TCPDF
。
当我使用TCPDF
出现此错误:在使用pthreads创建的线程中使用TCPDF
“通知:未定义的变量:_ SERVER中......”
如何,我必须解决这个问题?
$_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
。