php多线程

作者:fly 发布于:2014-2-4 15:09 分类:discuz

<?php

$th=new thread(10);//10个线程
$th->exec('demo');//执行自定义的函数

function demo() {
        fopen('data/'.microtime(),'w');
}

class thread {
        var $count;
        function thread($count=1) {

                $this->count=$count;
        }
   
           function _submit() {
                for($i=1;$i<=$this->count;$i++) $this->_thread(); 
                return true;
        }

        function _thread() {
                $fp=fsockopen($_SERVER['HTTP_HOST'],80); 
                fputs($fp,"GET $_SERVER[PHP_SELF]?flag=1\r\n"); 
                fclose($fp); 
        }
        
        function exec($func) {
                isset($_GET['flag'])?call_user_func($func):$this->_submit(); 
        }


}

?> 

发表评论:

 
Powered by emlog sitemap