对象变量在PHP pthread中丢失上下文

我在PHP中使用pthreads时,发现pthreads在其上下文中丢失了对象变量,这是正常现象还是Bug,或者我做错了什么?

class Downloader extends Thread {

    private $ch;

    public function __construct($data) {
        $this->ch = curl_init();
    }

    public function __destruct() {
        curl_close($this->ch);
    }

    public function run() {
        // we just lost resource of curl -> [resource(4) of type (Unknown)]
        curl_setopt($this->ch, CURLOPT_URL, $this->url);
    }
}

解决方法:

正常:7000

我没有必要再写出相关的部分.阅读全文将使您受益.

TL; DR资源在官方上不受支持,再加上pthreads对象如何工作,这会导致您遇到的行为.

上一篇:c-如何终止正在等待信号量操作的线程


下一篇:pthread和C