PHP Mongo Error reading from socket

前端 未结 2 668
野性不改
野性不改 2020-12-19 17:59

The last couple of days, my error log has been filled with this error:

send_package: error reading from socket: The socket is closed

I real

相关标签:
2条回答
  • 2020-12-19 18:17

    Increasing timeouts may help.

    • "socketTimeoutMS" : How long a send or receive on a socket can take before timing out.
    • "wTimeoutMS" : It controls how many milliseconds the server waits for the write concern to be satisfied.
    • "connectTimeoutMS" : How long a connection can take to be opened before timing out in milliseconds.

      $m = new MongoClient("mongodb://127.0.0.1:27017", array("connect"=>TRUE, "connectTimeoutMS"=>10, "socketTimeoutMS"=>10, "wTimeoutMS"=>10));
      
          $db= $m->mydb;
          $coll = $db->testData;
          $coll->insert($paramArr);
      
    0 讨论(0)
  • 2020-12-19 18:24

    There is a known issue with PHP/mongoclient + Apache + MongoDB where invalid persistent connections are held open by the Apache process.

    Try to restart your Apache web server.

    What happens is:

    • Apache opens a connection to your MongoDB server during a normal request.
    • Presumably, at some point you have restarted your MongoDB server
    • Apache/PHP never recognize that the connection was closed during the MongoDB restart and hold on to the persistent connections opened previously

    The only way to get past this issue is to restart Apache (forcing it to kill all of the worker threads and create new connections).

    Let me know if this works for you.

    0 讨论(0)
提交回复
热议问题