-
-
/** - *Based on PHP5
- *With the help of proc_open
- * you can start multiple processes, you can use your imagination to do what you want
- *If you are running php on Linux and enable the pcntl module, use the pcntl function. Better
- *Last modified: by bbs.it-home.org 2013/6/20
- **/
- error_reporting(E_ALL);
- set_time_limit(0);
class Thread {
- protected $_pref; // process reference
- protected static $_instance = null;
- protected $_pipes;
private function __construct() {
- $this->_pref = 0;
- }
public static function getInstance($file) {
- if (null == self::$_instance) {
- self::$_instance = new self;
- }
$descriptor = array(
- 0 => array("pipe", "r"),
- 1 => array("pipe", "w"),
- 2 => array("file", "./error-output.txt", "a"),
- );
- self::$_instance->_pref = proc_open("php -q $file", $descriptor, self::$_instance->_pipes);
- return true;
- }
public function __destruct() {
- proc_close($this->_pref);
- $this->_pref = null;
- }
- ?>
-
复制代码
|