reasno / fastmongo Goto Github PK
View Code? Open in Web Editor NEW🔌 Plug & Play Mongodb driver for Hyperf (With Coroutine!)
License: MIT License
🔌 Plug & Play Mongodb driver for Hyperf (With Coroutine!)
License: MIT License
Warning: Swoole\Process::exec(): execv(/bhshejiao/vendor/bin/mongo-proxy-linux-amd64) failed, Error: Exec format error[8] in /bhshejiao/vendor/hyperf/gotask/src/Process/GoTaskProcess.php on line 65
$collection = $mongo->database('supsite')->collection('data_article');
$data = $collection->find(['siteid' => $siteid], ['skip'=>0,'limit'=>15]);
var_dump(count($data));
collection 实际570条数据 limit = 1 时查出的数据正常 但limit 15 return 了全部数据 570
在Controller 中 MongoClient 正常使用.
但在 Hyperf Command 中. 就發生錯誤,
我已經使用一個全新的Hyperf 2.0去測試這問題, ,
發現每當運行 php bin/hyperf.php start 時.. 都會在/tmp /中建立一個 {app name}_{XXXX}.sock 的file .
但運行Hyperf Command時, tmp /中 並沒有新增相關的sock file. 而出現以下錯誤.
[WARNING] RemoteGoTask::__call failed, because unable to establish connection unix:///tmp/skeleton_5f363719a4f47.sock PHP Fatal error: Uncaught Spiral\Goridge\Exceptions\RelayException: No such file or directory (2) in /hyperf-skeleton/vendor/hyperf/gotask/src/Relay/CoroutineSocketRelay.php:134
以下是composer.json
"require": { "php": ">=7.2", "ext-swoole": ">=4.5", "hyperf/cache": "~2.0.0", "hyperf/command": "^2.0", "hyperf/config": "~2.0.0", "hyperf/db-connection": "~2.0.0", "hyperf/framework": "~2.0.0", "hyperf/guzzle": "~2.0.0", "hyperf/http-server": "~2.0.0", "hyperf/logger": "~2.0.0", "hyperf/memory": "~2.0.0", "hyperf/process": "~2.0.0", "hyperf/redis": "~2.0.0", "hyperf/async-queue": "~2.0.0", "reasno/fastmongo": "^0.2.1" },
readme里面的例子太少了,且都是普通查询相关的,别的一些聚合操作,函数都没有。请问有更完整一些的文档吗。
首先感谢作者的辛苦努力,非常高效。
但是在使用过程中,获得_id 字符串实在很费力。
例如获取插入后的_id,恕我能力太差,实在不知道这个对象在PHP下怎么快速得到一个string的_id。
协程
<?php
$max = 10000;
$co = new Coroutine\Concurrent(10);
$startTime = microtime(true);
for ($i=0; $i<$max; $i++){
$co->create(function() {
$condtion = ['adset_id' => '111'.rand(1, 10000)];
$data = ['adset_id' => '111', 'test'=> rand(1, 10000)];
try {
$this->mongoClient->updateByCondition($condtion, $data);
} catch (\Exception $e){
return $this->json(500, ['error'=>$e->getMessage()]);
}
});
}
$endTime = microtime(true);
$time = $endTime - $startTime;
直接for循环
<?php
$max = 10000;
$co = new Coroutine\Concurrent(10);
$startTime = microtime(true);
for ($i=0; $i<$max; $i++){
$co->create(function() {
$condtion = ['adset_id' => '111'.rand(1, 10000)];
$data = ['adset_id' => '111', 'test'=> rand(1, 10000)];
try {
$this->mongoClient->updateByCondition($condtion, $data);
} catch (\Exception $e){
return $this->json(500, ['error'=>$e->getMessage()]);
}
});
}
$endTime = microtime(true);
$time = $endTime - $startTime;
直接for循环40多秒写完,用协程调用一直卡着
[WARNING] RemoteGoTask::__call failed, because error 'error while executing mongo command: mongo: no documents in result' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
[ERROR] error 'error while executing mongo command: mongo: no documents in result' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'[123] in /www_home/modocenter-server_push/vendor/spiral/goridge/src/RPC.php
[ERROR] #0 /www_home/modocenter-server_push/vendor/spiral/goridge/src/RPC.php(107): Spiral\Goridge\RPC->handleBody()
#1 /www_home/modocenter-server_push/vendor/hyperf/gotask/src/IPC/SocketIPCSender.php(55): Spiral\Goridge\RPC->call()
#2 /www_home/modocenter-server_push/vendor/hyperf/gotask/src/GoTaskConnection.php(89): Hyperf\GoTask\IPC\SocketIPCSender->call()
#3 /www_home/modocenter-server_push/vendor/hyperf/gotask/src/GoTaskConnection.php(50): Hyperf\GoTask\GoTaskConnection->retry()
#4 /www_home/modocenter-server_push/vendor/hyperf/gotask/src/SocketGoTask.php(41): Hyperf\GoTask\GoTaskConnection->__call()
连接池是在哪里可以配置,有人知道吗?
Can provide the arm version of mongo-proxy?
$result = $this->db->collection('xxx')->updateOne(['_id'=> ‘xxxxx’], ['$set'=> ['fd'=> 'xxxx']]);
这样做,更新不成功,麻烦告诉下,谢谢
Hyperf\GoTask\MongoClient\Type\UpdateResult Object
(
[matchedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[modifiedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[upsertedCount:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] => 0
[upsertedId:Hyperf\GoTask\MongoClient\Type\UpdateResult:private] =>
)
这个是打印的$result返回值
确定updateOne里面的数据是无误的
我试过用其他字段修改是成功的,但是改用 _id 之后就不行了
按照说明引入了该包,使用依赖注入引入 MongoClient,如下调用:
class IndexController extends AbstractController
{
/**
* @Inject()
* @var MongoClient
*/
private MongoClient $mongoClient;
public function index()
{
$user = $this->request->input('user', 'Megalodon');
$method = $this->request->getMethod();
return [
'method' => $method,
'message' => "Hello {$user}.",
'test' => $this->mongoClient->credit->test,// 空对象
'test2' => $this->mongoClient->credit->test->find(),// 报错
];
}
}
完整错误信息:
[WARNING] RemoteGoTask::__call failed, because error '{rawData} request for <*mongo_client.FindCmd Value>' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
[ERROR] error '{rawData} request for <*mongo_client.FindCmd Value>' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'[123] in /www/credit-model-backend/vendor/spiral/goridge/src/RPC.php
项目中要使用多个mongo,怎么修改可以支持连接多个mongo
想问下通过边车进程的连接有连接池的概念吗,我在循环写入(1w左右)mongo集合的时候回碰到这种错误,好像大概率是因为连接数的问题导致的。
RemoteGoTask::__call failed, because error 'error while executing mongo command: connection(xxx-ip) incomplete read of message header: EOF' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
Spiral\Goridge\Exceptions\ServiceException : error 'error while executing mongo command: server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: xxx, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : dial tcp xxx: connect: connection refused }, { Addr: xxx, Type: RSSecondary, State: Connected, Average RTT: 14362421 }, ] }' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
@Reasno Is it possible to release a version upgrading hyperf/gotask
dependency to ^3.0?
Thanks!
如题。
因为并不清楚是否需要mongdb的支持,所以先安装了本组件,测试环境有mgdb是没问题的,但是正式环境还没有mgdb,没有的情况下是无法启动框架的,我该怎么关掉这个组件?
执行 php bin/hyperf.php vendor:publish reasno/fastmongo时候报/hyperf-project/config/autoload/mongodb.php] already exists错误
updateOne如果只更新一个字段内容是怎么做?文本类型的
求助,findOne 怎么返回指定字段,不返回_id
$col->findOne(['account' => '小米'],['account'=>1,'_id'=>0]); 这样写没有起效果。
$col->updateOne(['_id'=>$id], ['$inc' => ['age' => 1]]);
这样更新内容不成功,是我写的不对吗?
报错:
error while executing mongo command: connection() : auth error: sasl conversation error: unable to authenticate using mechanism \"SCRAM-SHA-256\": (AuthenticationFailed) Authentication failed.
而且本地 docker 和线上 docker 配置是一样的,本地曾经出现过这个问题,但是是因为把 host 写成了 127.0.0.1 而不是 docker 容器名,本地改了就好了。但线上怎么改都有这个问题。
unable to authenticate using mechanism \"SCRAM-SHA-256\": (AuthenticationFailed)
MongoDB版本:4.1
Hyperf 版本:2.2
时不时会出现:链接被拒绝的报错
[WARNING] RemoteGoTask::__call failed, because unable to establish connection tcp://127.0.0.1:6001: Connection refused (111) [ERROR] Spiral\Goridge\Exceptions\RelayException: unable to establish connection tcp://127.0.0.1:6001: Connection refused (111)(0) in phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/Relay/CoroutineSocketRelay.php:137 Stack trace: #0 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/Relay/SocketTransporter.php(35): Hyperf\GoTask\Relay\CoroutineSocketRelay->connect() #1 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/spiral/goridge/src/RPC.php(48): Hyperf\GoTask\Relay\CoroutineSocketRelay->send() #2 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/IPC/SocketIPCSender.php(55): Spiral\Goridge\RPC->call() #3 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/GoTaskConnection.php(89): Hyperf\GoTask\IPC\SocketIPCSender->call() #4 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/GoTaskConnection.php(50): Hyperf\GoTask\GoTaskConnection->retry() #5 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/SocketGoTask.php(41): Hyperf\GoTask\GoTaskConnection->__call() #6 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/GoTaskProxy.php(39): Hyperf\GoTask\SocketGoTask->call() #7 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/MongoClient/MongoProxy.php(76): Hyperf\GoTask\GoTaskProxy->call() #8 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/gotask/src/MongoClient/Collection.php(84): Hyperf\GoTask\MongoClient\MongoProxy->find() #9 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/app/Mongo/Base.php(64): Hyperf\GoTask\MongoClient\Collection->find() #10 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/runtime/container/proxy/App_Process_CommonQueue.proxy.php(197): App\Mongo\Base->find() #11 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/runtime/container/proxy/App_Process_CommonQueue.proxy.php(45): App\Process\CommonQueue->check_state() #12 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/runtime/container/proxy/App_Process_CommunityQueue.proxy.php(56): App\Process\CommonQueue->handle() #13 phar:///www_home/modocenter-server_push/modocenter-push-v5.0.10.phar/vendor/hyperf/process/src/AbstractProcess.php(134): App\Process\CommunityQueue->handle() #14 {main}
php 版本信息
PHP 7.4.24 (cli) (built: Oct 3 2021 19:22:29) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Yasd v0.3.9-alpha, Our Copyright, by codinghuang
swoole 信息
`swoole
Swoole => enabled
Author => Swoole Team [email protected]
Version => 4.8.0
Built => Oct 15 2021 14:01:04
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips 26 Jan 2017
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled
Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608`
[WARNING] RemoteGoTask::__call failed, because error 'error while executing mongo command: (Unauthorized) command insert requires authentication' on 'Hyperf\GoTask\Relay\CoroutineSocketRelay'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.