anyway what happens is
- parent opens db connection
$db
- parent forks child worker, which inherits the connection resource
- child worker does some work and exits (successfully or not)
- php cleans up any open resource handles,
$db
among them. - parent thinks
$db
is still a valid resource. - parent tries to access it, or parent forks a new child and gives it the invalid handle...
- php goes boom, because it tries to use an invalid connection resource.
solution?
make sure to open your db connections explicitly in the child worker. Things are worse if you are using a singleton such as above, because the db connection is hidden from you and you are not even aware that it was reused, so you have to explicitly close the connection in the worker constructor before calling Database::query() for example.