weixin_39884492 2020-11-20 22:29
浏览 0

Server shutdown terminates scripts hanging on event streams

Description

Server shutdown causes any PHP script hanging on an event stream to receive a SIGTERM signal and exit, bypassing all normal error handlers.

Using the pcntl extension I'm able to keep my script running and reconnect every X seconds. When the signal is ignored I'm able to catch exceptions that are thrown out of the driver.

e.g.

php
pcntl_signal( SIGTERM, SIG_IGN );
while ( true ){
  try {
    // connect and do cool stream stuff
  }
  catch( Exception $e ){
    sleep(5);
  }
}

This is all good, except I don't know what other signals could occur. Is SIGTERM the only likely signal I need to catch?

Also, it feels like forced script termination isn't good driver behaviour when a server connection disappears. Is this intentional, or unavoidable?

Environment


Mac OS 10.14.4
PHP 7.2.16

libbson bundled version => 1.13.0
libmongoc bundled version => 1.13.0
libmongoc SSL => enabled
libmongoc SSL library => Secure Transport
libmongoc crypto => enabled
libmongoc crypto library => Common Crypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
libmongoc ICU => enabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
mongodb.debug => no value => no value

Many thanks. Loving event streams so far!

该提问来源于开源项目:mongodb/mongo-php-driver

  • 写回答

0条回答 默认 最新

    报告相同问题?