Git Product home page Git Product logo

swoole-mongo's Introduction

Nonblocking MongoDB Connection in Swoole

While there is no official mongodb client for swoole and PHP mongodb-ext is blocking as mentioned here and demonstrated here we can use swoole coroutine client to run our queries agains MongoDB in a nonblocking manner using MongoDB Wire Protocol. This is my naive implementation of this idea.

Set up

$ docker-compose up -d

Test

The application has three routes as follows:

  • http://localhost:9501 Use this route to test if the application is responsive while your request to any of the other two routes is in progress it should resolve immediately for the right route and it should hang for the wrong route.
  • http://localhost:9501?wrong This route uses the mongodb extension to run a slow query against database so it responds after 10 seconds and blocks all other calls
  • http://localhost:9501?right This route uses MongoDB wire protocol and swoole coroutine client to run a slow query against database so it responds after 10 seconds but it does not block other calls

Errors

If the solution fails to start make sure that the src/application is executable or change the CMD section in the Dockerfile to:

CMD ["php", "application"]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.