在php中使用线程

时间:2018-04-12 19:59:16

标签: php multithreading

我正在尝试在php中学习线程并尝试并行执行三个线程。这是我的代码

        $set = "abcacbabccbacab";
    $_set = $set;
    echo "S = {".$_set."}<br/>";
    $rule1 = new Rule1($_set);
     $rule2 = new Rule2($_set);
      $rule3 = new Rule3($_set);
    $_set = $rule1->run();
    $_set = $rule2->run();
    $_set = $rule3->run();
    echo "S` = {".$_set."}<br/><br/>";

class Rule1 extends Thread
{
public function __construct($set)
{
    $this->set = $set;
}
public function run()
{
    $check = false;
        $set = str_replace("abc", "aab", $set);
        $check = true;

    return $set;
}
}

class Rule2 extends Thread
{
public function __construct($set)
{
    $this->set = $set;
}
public function run()
{
    $check = false;
        $set = str_replace("ac", "ba", $set);
        $check = true;

    return $set;
}
}

class Rule3 extends Thread
{
public function __construct($set)
{
    $this->set = $set;
}
public function run()
{
    $check = false;
        $set = str_replace("cb", "cc", $set);
        $check = true;

    return $set;
}
}

但是,每当我尝试运行应用程序时,它都会抛出此错误

未捕获错误:找不到“Rule1”类

即使该类的名称为Rule1,但它仍然显示。

0 个答案:

没有答案