Concurrent.php
2.28 KB
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
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-4-25
* Time: 0:49
*/
class Q_Webservice_Yar_Concurrent
{
private $_callback;
private $package = array();
private $functionName;
private $url;
private $requestUrl;
public function __construct($url = '')
{
$this->url = $url;
$this->requestUrl = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
}
function callFunction($functionName, array $parameters = array(), $callback = null, array $opt = array())
{
$this->package['call_time'] = microtime(true);
$this->package['function_name'] = $this->functionName = $functionName;
$this->package['referer'] = $this->requestUrl;
$this->package['service_url'] = $this->url;
$this->package['parameter'] = $parameters;
$_callback = null;
if (!empty($callback)) {
$this->_callback = $callback;
$_callback = array($this, 'callback');
}
Yar_Concurrent_Client::call($this->url, $functionName, $parameters, $_callback, NULL, $opt);
}
function call($url, $functionName, array $parameters = array(), $callback = null, array $opt = array())
{
$this->package['call_time'] = microtime(true);
$this->package['function_name'] = $this->functionName = $functionName;
$this->package['referer'] = $this->requestUrl;
$this->package['service_url'] = $this->url = $url;
$this->package['parameter'] = $parameters;
$_callback = null;
if (!empty($callback)) {
$this->_callback = $callback;
$_callback = array($this, 'callback');
}
Yar_Concurrent_Client::call($url, $functionName, $parameters, $_callback, NULL, $opt);
}
public function callback($callBackData)
{
$this->package['result_time'] = microtime(true);
$this->package['result'] = $callBackData;
QAid_Logs_Record::yar($this->package);
$callinfo = array(
'uri' => $this->url,
'method' => $this->functionName
);
call_user_func_array($this->_callback, array($callBackData, $callinfo));
}
function loop($callback = null, $error_callback = null)
{
Yar_Concurrent_Client::loop($callback, $error_callback);
}
}