代码拉取完成,页面将自动刷新
同步操作将从 郭新华/php-cp 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
class asyncRedisProxy {
private $redisProxy = null;
private $syncFunArr;
private $map; //fd=>obj
public function __construct() {
$this->redisProxy = new redisProxy();
$this->syncFunArr = array(
'connect',
'pconnect'
);
$this->redisProxy->setAsync(1);
}
/*
* every obj have a tcp with pool_server,so close it when __destruct
*/
public function __destruct() {
$this->redisProxy->close();
}
public function __call($name, $arguments) {
if (in_array($name, $this->syncFunArr)) {
if (is_callable(end($arguments))) {
throw new Exception("the function " . json_encode($this->syncFunArr) . " can not async");
}
return call_user_func_array(array($this->redisProxy, $name), $arguments);
}
if (is_callable(end($arguments))) {//can async and last args is callback
$callback = array_pop($arguments);
$this->redisProxy->setAsync(1);
$fd = call_user_func_array(array($this->redisProxy, $name), $arguments);
$this->map[$fd] = $this->redisProxy;
swoole_event_add($fd, function($fd) use ($callback) {
swoole_event_del($fd);
$data = $this->map[$fd]->done(); //set sync
call_user_func($callback, $this, $data);
});
} else {
return call_user_func_array(array($this->redisProxy, $name), $arguments);
}
}
}
class asyncPdoProxy {
private $pdoProxy = null;
private $syncFunArr;
private $map; //fd=>obj
public function __construct($dns, $user, $pwd, $arr = array()) {
$this->pdoProxy = new pdoProxy($dns, $user, $pwd, $arr);
$this->asyncFunArr = array(
'exec',
'query',
'commit'
);
$this->pdoProxy->setAsync(1); //set the next cmd async/sync
}
/*
* every obj have a tcp with pool_server,so close it when __destruct
*/
public function __destruct() {
$this->pdoProxy->close();
}
public function __call($name, $arguments) {
if (in_array($name, $this->asyncFunArr)) {
if (is_callable(end($arguments))) {//can async and last args is callback
$callback = array_pop($arguments);
$this->pdoProxy->setAsync(1); //set pdo async
$fd = call_user_func_array(array($this->pdoProxy, $name), $arguments);
$this->map[$fd] = $this->pdoProxy;
swoole_event_add($fd, function($fd) use ($callback) {
swoole_event_del($fd);
$data = $this->map[$fd]->done(); //set pdo sync inner
call_user_func($callback, $this, $data);
});
} else {
$this->pdoProxy->setAsync(0); //set pdo sync
return call_user_func_array(array($this->pdoProxy, $name), $arguments);
}
} else {
if (is_callable(end($arguments))) {
throw new Exception("only the function " . json_encode($this->syncFunArr) . " can be async");
}
$this->pdoProxy->setAsync(0); //set pdo sync
$data = call_user_func_array(array($this->pdoProxy, $name), $arguments);
if (is_object($data)) {
$stmt = new asyncSTMTProxy(); //warpper it
$stmt->setSTMTObj($data);
$stmt->setPDOObj($this->pdoProxy);
$data->setAsync(0); //set stmt async
return $stmt;
} else {
return $data;
}
}
}
}
class asyncSTMTProxy {
private $stmtProxy = null;
private $pdoProxy = null;
private $syncFunArr;
private $map; //fd=>obj
private $asyncFunArr = array(
'execute',
);
public function setSTMTObj($obj) {
$this->stmtProxy = $obj;
}
public function setPDOObj($obj) {
$this->pdoProxy = $obj;
}
public function __call($name, $arguments) {
if (in_array($name, $this->asyncFunArr)) {
if (is_callable(end($arguments))) {//can async and last args is callback
$callback = array_pop($arguments);
$this->stmtProxy->setAsync(1); //set pdo async
$fd = call_user_func_array(array($this->stmtProxy, $name), $arguments);
$this->map[$fd] = $this->stmtProxy;
swoole_event_add($fd, function($fd) use ($callback) {
swoole_event_del($fd);
$data = $this->map[$fd]->done(); //set pdo sync
call_user_func($callback, $this->stmtProxy, $data);
});
} else {
$this->stmtProxy->setAsync(0); //set pdo sync
return call_user_func_array(array($this->stmtProxy, $name), $arguments);
}
} else {
if (is_callable(end($arguments))) {
throw new Exception("only the function " . json_encode($this->syncFunArr) . " can be async");
}
$this->stmtProxy->setAsync(0); //set pdo sync
return call_user_func_array(array($this->stmtProxy, $name), $arguments);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。