当前位置:网站首页>How PHP drives mongodb
How PHP drives mongodb
2022-07-03 21:35:00 【Yisu cloud】
PHP How to drive MongoDB
This article mainly introduces “PHP How to drive MongoDB”, In daily operation , I believe a lot of people are PHP How to drive MongoDB There are doubts about the problem , Xiao Bian consulted all kinds of materials , Sort out simple and easy-to-use operation methods , I hope to answer ”PHP How to drive MongoDB” Your doubts help ! Next , Please follow Xiaobian to learn !
MongoDB It's a by C++ language-written , Database based on distributed file storage .MongoDB Is a product between relational and non-relational databases , Non-relational databases are the most versatile , Most like a relational database .

When and mongodb When the replica set is connected , The driver first attempts to connect and verify each non Hidden node . If a node is “down” state , Will skip .
Creating an index sometimes blocks new connections
However , If a node is “UP” state , But with a write lock , Then the verification cannot be carried out , So the driver will be suspended .
stay mongodb 2.6 Before version , Common problems in indexing . All indexes are created in the foreground or background , stay secondary The end will be created in the foreground .
stay PHP Driver's 1.5.3 The version will be improved , When the index is created , Allow verification to second Node validation .
Reduce is_master_interval value
For applications that require high availability , It is recommended to check the configuration settings of the default driver runtime .
mongo.is_master_interval Option controls how the driver recovers quickly when the replica set is re elected .
is_master_interval The default value of the option is 15s, Set the driver to send “isMaster” Ask for each mongod Time interval of the instance . These requests help the driver determine the topology of the replication set , Specifically , It is to request to detect which node is primary And can receive write operations .
It is recommended that the value be set to 1 or 2 second , So that when the driver is in cluster election or failover , Can quickly locate primary node . Of course! , It also depends on how many clients there are and ping The frequency of .
Be careful , When primary When a node changes , Such as election or failover , There will always be a few seconds for the driver to receive a “MongoConnectionException” Information “No candidate servers found”. These exceptions need to be handled in your code , Otherwise, the application will be terminated .
Understand how connections are handled and configure connections TimeoutMS
PHP The driver does not use connection pooling . therefore , I suggest you every PHP The process creates a connection . however , If web There are many applications PHP Working process , Many new database connections will be created ,PHP Drivers cannot share connections between processes . therefore , When network nodes are slow , The server When busy ,PHP Applications are particularly vulnerable to obstacles when creating initial database connections .
under these circumstances , It is recommended that you customize connectionTimeoutMS Options and notes php.ini Medium mongo.ping_interval Options .
connectionTimeoutMS
PHP The driver does not define a default connection timeout . contrary , The default value is php.ini In the document default_socket_timeout The choice decides , The default is 60 second . The connection will wait 60 Seconds off , It's been a long time , It needs to be reduced .
It is strongly recommended to connect the string through URI Options display settings connectionTimeoutMS Options . Set it to 5 To 30 The value between seconds .
mongo.ping_interval
mongo.ping_interval The default value is 5 second . This option sets the driver to send ping Request to each mongod Instance discovery “down” Time interval of nodes , Blacklist of servers used to track drivers . Tell the driver which nodes to ignore .
Here we are , About “PHP How to drive MongoDB” That's the end of my study , I hope we can solve your doubts . The combination of theory and practice can better help you learn , Let's try ! If you want to continue to learn more related knowledge , Please continue to pay attention to Yisu cloud website , Xiaobian will continue to strive to bring you more practical articles !
边栏推荐
- (5) Web security | penetration testing | network security operating system database third-party security, with basic use of nmap and masscan
- Basic number theory -- Chinese remainder theorem
- Design e-commerce seckill system
- Leetcode daily question 540 A single element in an ordered array Valentine's Day special article looking for a single dog in a pile of lovers ~ the clown is myself
- MySQL——规范数据库设计
- MySQL——SQL注入问题
- Decompile and modify the non source exe or DLL with dnspy
- MySQL——数据库备份
- Mysql database ----- common commands of database (based on database)
- Under the double reduction policy, research travel may become a big winner
猜你喜欢
Après 90 ans, j'ai démissionné pour démarrer une entreprise et j'ai dit que j'allais détruire la base de données Cloud.
Capture de paquets et tri du contenu externe - - autoresponder, composer, statistiques [3]
Rhcsa third day notes
(5) Web security | penetration testing | network security operating system database third-party security, with basic use of nmap and masscan
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
Study diary: February 14th, 2022
Memory analyzer (MAT)
Etcd raft Based Consistency assurance
Experience summary of database storage selection
Such as the visual appeal of the live broadcast of NBA Finals, can you still see it like this?
随机推荐
常用sql集合
The post-90s resigned and started a business, saying they would kill cloud database
Scientific research document management Zotero
技术管理进阶——如何在面试中考察候选人并增大入职概率
Software testing skills, JMeter stress testing tutorial, obtaining post request data in x-www-form-urlencoded format (24)
请教大家一个问题,用人用过flink sql的异步io关联MySQL中的维表吗?我按照官网设置了各种
Summary of common operation and maintenance commands
Implementation principle of inheritance, encapsulation and polymorphism
Remember the experience of automatically jumping to spinach station when the home page was tampered with
Common SQL sets
Tidb's initial experience of ticdc6.0
仿网易云音乐小程序
Yyds dry inventory hcie security Day12: concept of supplementary package filtering and security policy
treevalue——Master Nested Data Like Tensor
Mysql database ----- common commands of database (based on database)
Pengcheng cup Web_ WP
Global and Chinese market of gallic acid 2022-2028: Research Report on technology, participants, trends, market size and share
Is it OK for fresh students to change careers to do software testing? The senior answered with his own experience
Quickly distinguish slices and arrays
Mysql - - Index