【问题标题】:PHP pthreads: the lack of resource errorPHP pthreads:缺少资源错误
【发布时间】:2014-07-07 08:32:47
【问题描述】:

刚刚收到 PHP pthreads 错误

pthreads 检测到无法启动多线程,系统缺少必要的资源或将超出系统施加的限制

无法初始化 zend_mm 存储 [win32]

在我的脚本中...

PHP 代码如下所示:

class multihread extends Worker  {
    public $result;
    function __construct($e) {
        $this->e = $e;
    }
    public function run() {
        $this->result=file($this->e);
    }
}



$threads = 15;
do {
    for($i=1; $i<=$threads; $i++) {
        if(empty($thread[$i])){
            $e=generate_e($i);
            if($e==false){
                echo "Warning: no more job for e. exiting A"; exit;
            }
            echo "Starting new thread $i \n";
            $thread[$i] = new multihread($e);
            $thread[$i]->start(PTHREADS_INHERIT_NONE);
        }
        elseif($thread[$i]->isWorking()===false) {
            if($thread[$i]->result===false){
                echo "ERROR:Something wrong with thread $i, exit.";
                exit;
            }
            $thread[$i]->shutdown();
            $eval=generate_e($i);
            if($e==false){
                echo "Warning: no more job exiting B"; exit;
            }
            $thread[$i] = new multihread($e);
            $thread[$i]->start(PTHREADS_INHERIT_NONE);
        }
    }
    usleep(100);
}
while(1);

因此,脚本打开新线程,启动该线程,然后使用 shutdown() 关闭线程并在循环中执行。它就像魅力一样工作,但在 16000 多个打开\关闭的线程后出现此错误。似乎有些资源保持锁定状态?如何解决这个问题?

【问题讨论】:

    标签: php multithreading pthreads


    【解决方案1】:

    一个人应该在线程结束之前detach(),或者在它上面调用join()等待它结束。

    如所观察到的那样,缺少一个或另一个会导致线程的资源被释放,尽管系统资源耗尽。

    【讨论】:

    • 谢谢,但问题是脚本使用Worker 而不是Thread,我不知道如何detachworker
    • WorkerThread继承join()detach()方法:php.net/manual/en/class.worker.php@user3742227
    猜你喜欢
    • 2015-10-04
    • 2012-04-13
    • 2020-10-02
    • 2011-03-09
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2010-10-17
    • 2013-04-13
    相关资源
    最近更新 更多