代码拉取完成,页面将自动刷新
同步操作将从 牧牧枫cc123/Group-Co 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
$start = microtime(true);
//设置2秒超时
service("user")->setTimeout(2);
$users = (yield service("user")->call("User\User::getUsersCache", ['ids' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]));
dump($users);
$start = microtime(true);
//设置2秒超时
service("user")->setTimeout(2);
$callId1 = service("user")->addCall("User\User::getUsersCache", ['ids' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]);
$callId2 = service("user")->addCall("User\User::getUser", ['id' => 1]);
$res = (yield service("user")->multiCall());
dump($res[$callId1]);
dump($res[$callId2]);
dump(microtime(true) - $start);
use AsyncRedis;
//关闭连接池
\AsyncRedis::enablePool(false);
//开启连接池
\AsyncRedis::enablePool(true);
//设置超时时间
AsyncRedis::setTimeout(2);
yield AsyncRedis::set('foo', 'bar');
dump(yield AsyncRedis::get('foo'));
$user = json_encode(['foo' => 'bar']);
yield AsyncRedis::hSet('user', 1, $user);
dump(yield AsyncRedis::hGet('user', 1));
use AsyncMysql;
//第二个参数设为false将不会使用连接池中的资源,默认都会从连接池中取,配置连接池数量 => config/database.php
AsyncMysql::query($sql, $usePool = true);
//设置超时时间
AsyncMysql::setTimeout(2);
$res = (yield AsyncMysql::query("INSERT INTO `user` (`id`, `mobile`, `password`) VALUES (NULL, '18768122222', '11111')"));
//失败返回false
if ($res) {
$result = $res->getResult();
$affectedRows = $res->getAffectedRows();
$id = $res->getInsertId();
}
use AsyncMysql;
public function test()
{
try {
yield AsyncMysql::begin();
$res = (yield $this->doTrans());
if ($res === false) {
throw new \Exception("need roll back");
}
yield AsyncMysql::commit();
} catch (\Exception $e) {
yield AsyncMysql::rollback();
}
}
public function doTrans()
{
$res = (yield AsyncMysql::query("INSERT INTO `user` (`id`, `mobile`, `password`) VALUES (NULL, '187681343332', '11111')"));
if ($res) {
$result = $res->getResult();
$affectedRows = $res->getAffectedRows();
$id = $res->getInsertId();
$res = (yield AsyncMysql::query("SELECT * FROM `user` WHERE id = {$id}"));
$res = (yield AsyncMysql::query("SELECT * FROM `user`"));
$res = (yield AsyncMysql::query("DELETE FROM `user` WHERE id = {$id}", false));
}
yield true;
}
use AsyncLog;
yield AsyncLog::info('hello world');
yield AsyncLog::debug('test debug', ['foo' => 'bar']);
yield AsyncLog::notice('hello world',[], 'group.com');
yield AsyncLog::warning('hello world');
yield AsyncLog::error('hello world');
yield AsyncLog::critical('hello world');
yield AsyncLog::alert('hello world');
yield AsyncLog::emergency('hello world');
use AsyncFile;
$content = (yield AsyncFile::read(__ROOT__."runtime/test.txt"));
$res = (yield AsyncFile::write(__ROOT__."runtime/test.txt", "hello wordls!"));
$res = (yield AsyncFile::write(__ROOT__."runtime/test.txt", "hello wordls!", FILE_APPEND));
//如果在业务层不catch,框架层会捕捉,并返回一个500的server error响应。如果在开发环境会返回一个500的具体错误的trace响应。
try {
throw new \Exception("Error Processing Request", 1);
//yield throwException(new \Exception("Error Processing Request", 1));
} catch (\Exception $e) {
echo $e->getMessage();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。