Of course, anyone who has a deep understanding of multithreading knows that multithreading implemented through WEB servers can only imitate some of the effects of multithreading, not in the true sense. But in any case, it can still meet some of our needs, and can still be used in the need of multi-threaded features. 12345678910111213141516
Of course, anyone who has a deep understanding of multithreading knows that multithreading implemented through WEB servers can only imitate some of the effects of multithreading, not in the true sense. But in any case, it can still meet some of our needs, and can still be used in the need of multi-threaded features. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Of course, anyone who has a deep understanding of multithreading knows that multithreading implemented through WEB servers can only imitate some of the effects of multithreading, not in the true sense.
But in any case, it can still meet some of our needs, and can still be used in the need of features similar to multithreading.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/**
*
* PHP multithreading Application Usage:
* require_once 'thread.class.php';
* $thread = new thread();
* $thread->addthread('action_log','a');
* $thread->addthread('action_log','b');
* $thread->addthread('action_log','c');
* $thread->runthread();
*
* function action_log($info) {
* $log = 'log/' . microtime() . '.log';
* $txt = $info . "\r\n\r\n" . 'Set in ' . Date('h:i:s', time()) . (double)microtime() . "\r\n";
* $fp = fopen($log, 'w');
* fwrite($fp, $txt);
* fclose($fp);
* }
*/
class thread {
var$hooks = array();
var$args = array();
functionthread() {
}
functionaddthread($func)
{
$args= array_slice(func_get_args(), 1);
$this->hooks[] =$func;
$this->args[] =$args;
returntrue;
}
functionrunthread()
{
if(isset($_GET['flag']))
{
$flag= intval($_GET['flag']);
}
if($flag|| $flag === 0)
{
call_user_func_array($this->hooks[$flag],$this->args[$flag]);
}
else
{
for($i= 0, $size = count($this->hooks);$i < $size;$i++)
{
$fp=fsockopen($_SERVER['HTTP_HOST'],$_SERVER['SERVER_PORT']);
if($fp)
{
$out= "GET {$_SERVER['PHP_SELF']}?flag=$i HTTP/1.1\r\n";
$out.= "Host: {$_SERVER['HTTP_HOST']}\r\n";
$out.= "Connection: Close\r\n\r\n";
fputs($fp,$out);
fclose($fp);
}
}
}
}
}
|