【问题标题】:Object variable lose context in PHP pthreads对象变量在 PHP pthreads 中丢失上下文
【发布时间】:2017-08-24 09:41:52
【问题描述】:

我在 PHP 中使用 pthreads 并注意到 pthreads 在其上下文中丢失了对象变量,这是正常现象还是错误还是我做错了什么?

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);
    }
}

【问题讨论】:

    标签: php multithreading curl pthreads


    【解决方案1】:

    正常:https://gist.github.com/krakjoe/6437782

    我没有必要再把相关部分写出来;您将受益于阅读整篇文章。

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

    【讨论】:

      猜你喜欢
      • 2018-11-30
      • 1970-01-01
      • 2012-12-02
      • 2011-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多