小编Joh*_*hnF的帖子

PHP线程应如何存储其数据?

所以我一直在谷歌搜索和阅读有关PHP pthreads3以及它们应该如何存储数据的互联网.(或者更确切地说,它们不是这样)在我看来,线程正确存储其数据的唯一方法是创建一个新的Threaded对象并将其发送到线程.然后,线程可以使用此Threaded对象来存储几乎任何数据.

我的问题,以及掌握PHP线程的最大问题:是否有可能让线程在需要时创建自己的存储对象?我不知道如何或为什么,因为我在此发现的所有答案都说明了一个模糊,精细和令人困惑的"可能,但没有",主要与性能不佳和记忆问题/安全性有关.这似乎应该是可能的,不知何故:

class someFantasticThread extends Thread {
    public $someData;

    function run(){
        while(true){
            //Create a fresh storage for the new data this iteration
            $this->someData = new SomeCoolStorage(); // Can this work somehow without all the issues?
            $this->someData[] = 'amazingdata'; // Do something amazing and store the new results in $someData
            $this->someData[] = new SomeCoolStorage(); // This would also be desireable, if it can somehow be done
            //don't mind the obvious loop issues. Imagine this is a well formed loop
        } …
Run Code Online (Sandbox Code Playgroud)

php multithreading pthreads php-7.1

3
推荐指数
1
解决办法
1239
查看次数

标签 统计

multithreading ×1

php ×1

php-7.1 ×1

pthreads ×1