当前位置:Gxlcms > PHP教程 > phpthread扩展的使用

phpthread扩展的使用

时间:2021-07-01 10:21:17 帮助过:29人阅读

安装教程请参考thread安装

直接上一段简单的代码

classtestextendsThread {publicfunction__construct($fun)
 {$this->fun=$fun;
 }

  publicfunctionrun() {$param=$this->fun;
    $this->$param();
  }

  privatefunctiontest1()
  {echo1;
    echo"
"
; } privatefunctiontest2() { sleep(3); echo2; echo"
"
; } privatefunctiontest3() {echo3; echo"
"
; } } $arr=array('test1','test2','test3'); foreach ($arras$fun) { $th[]=new test($fun); } foreach ($thas$worker) { $worker->start(); }

输出结果是
1
3
2

test 类继承thread类,需要实现run方法,start方法会自动开启一个线程来执行run方法里的程序,thread具体的方法请参考官方手册
http://php.com/manual/zh/class.thread.php

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了php thread扩展的使用,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行