【问题标题】:php pthreads: 'PHP Fatal error' , 'Fatal error' in CLIphp pthreads:CLI 中的“PHP 致命错误”、“致命错误”
【发布时间】:2015-10-10 16:33:00
【问题描述】:

我在 CLI 中运行了https://github.com/krakjoe/pthreads/tree/seven/examples 的所有示例。 执行每一项后,除了预期结果外,我还得到 PHP Fatal error 和 Fatal error 。 例如在这种情况下https://github.com/krakjoe/pthreads/blob/seven/examples/ClosureFuture.php 我会得到:

object(Volatile)#6 (2) { 
[0]=> 
    string(5) "Hello" 
[1]=> 
    string(5) "World" 
} 
array(2) { 
[0]=> 
    string(5) "Hello" 
[1]=> 
    string(5) "World" 
}

PHP 致命错误:无法声明类 Future,因为该名称已在第 42 行的 /var/www/test/index1.php 中使用

致命错误:无法声明类 Future,因为该名称已在第 42 行的 /var/www/test/index1.php 中使用

在扩展类关闭时发生的所有示例错误。

您知道这些错误的原因以及如何纠正它们吗? 任何帮助将不胜感激。

class Future extends Thread {
    private function __construct(Closure $closure, array $args = []) {
        $this->closure = $closure;
        $this->args    = $args; 
    }
    public function run() {
        $this->synchronized(function() {
            $this->result = 
                ($this->closure)(...$this->args);
            $this->notify();
        });
    }
    public function getResult() {
        return $this->synchronized(function(){
            while (!$this->result)
                $this->wait();
            return $this->result;
        });
    }
    
    public static function of(Closure $closure, array $args = []) {
        $future = 
            new self($closure, $args);
        $future->start();
        return $future;
    }
    
    protected $owner;
    protected $closure;
    protected $args;
    protected $result;
}//line 42

【问题讨论】:

    标签: php pthreads


    【解决方案1】:

    检查您的服务器安装的 PHP 版本。根据 doc,它的支持来自 (PHP 5 >= 5.3.0)。

    【讨论】:

    • 感谢您的回复,我当前的php版本是5.5.8,我也在7.0.0RC4、7.0.0RC3、7.0.0RC2版本上测试过。
    【解决方案2】:

    听起来你可能发现了一个bug,或者pthreads中的一些bug,请在github上报告。

    请在报告中包含尽可能多的信息“致命错误”不是很有用。

    PHP7 和 pthreads v3 是预发布质量,引用的示例 ClosureFuture 刚刚在上次提交中更新,并进行了微小更改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 2012-06-24
      • 2018-05-26
      相关资源
      最近更新 更多