对象变量在PHP pthread中丢失上下文 [英] Object variable lose context in PHP pthreads

查看:54
本文介绍了对象变量在PHP pthread中丢失上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was working with pthreads in PHP and noticed that pthreads loses object variables in its context, is this normal or a bug or I'm doing something wrong ?

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

推荐答案

这是正常的: https://gist .github.com/krakjoe/6437782

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

There is no point in me writing the relevant parts out again; you will benefit from reading the whole article.

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

TL;DR Resources are officially unsupported, coupled with how pthreads objects work, this leads to the behaviour you are experiencing.

这篇关于对象变量在PHP pthread中丢失上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆