1. *基于*借助proc_open

  2. *能启动多进程,你可以使用你的想象力做你想做的了
  3. *如果你是在linux上跑*最后修改:by bbs.it-home.org 2013/6/20
  4. **/
  5. error_reporting(E_ALL);
  6. set_time_limit(0);

  7. class Thread {

  8. protected $_pref; // process reference
  9. protected static $_instance = null;
  10. protected $_pipes;

  11. private function __construct() {

  12. $this->_pref = 0;
  13. }

  14. public static function getInstance($file) {

  15. if (null == self::$_instance) {
  16. self::$_instance = new self;
  17. }

  18. $descriptor = array(

  19. 0 => array("pipe", "r"),
  20. 1 => array("pipe", "w"),
  21. 2 => array("file", "./error-output.txt", "a"),
  22. );
  23. self::$_instance->_pref = proc_open("_pipes);
  24. return true;
  25. }

  26. public function __destruct() {

  27. proc_close($this->_pref);
  28. $this->_pref = null;
  29. }
  30. ?>

复制代码


09-10 19:31