-
Notifications
You must be signed in to change notification settings - Fork 326
Fork kills connection? #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Fork dose not kill the connection,
Result:
|
@Timandes thanks. However, I don't think it is expected behavior. |
Memcache (without d) extension works as expected. Replacing
|
I can try to see if we can make this safe for forks. Not sure if libmemcached is |
What's happening is that the open connections are all inherited by the child process, but when the child process exits, cleanup begins: PHP calls the destructor functions for the memcached extension, which calls the destructor functions for libmemcached, which sends a Because the same connections are being used in the child as in the parent process, when the Note that because the same connections are being used, you have a risk to corrupt the stream of data to your memcached if the parent and child both try to read/write on the same connections. An approach to protecting against connection sharing would be to set FD_CLOEXEC on the sockets that libmemcached opens, so that after a fork the sockets are closed in the child. But the server list would still include those socket handles, so the first operation against each server in the child would go through the error/reconnect code path. Ironically, I think, in the destructor code path it might mean a reconnect followed immediately by a quit. Unfortunately I cannot find where in libmemcached I could get access to the file descriptors of the connections to each server in the fist place in order to set the FD_CLOEXEC flag. So I'm closing this as wont-fix. |
Sorry for asking after 3 years, but im hardly stuggling with it. We have cron manager which forks processes and then we access keys and stores them on using php-memcached and we have many weird issues like wrong values returned, empty values etc, totally random and unstable behavior. What we had after fork was exit(1), was trying to replace it with any of the:
But didn't solve the issue. Also tried to create new connection to memcache after forking a process(read it somewhere) but also doesn't seem to help with this. Does this basically means don't use php-memcached when forking processes? |
Code:
Output:
The text was updated successfully, but these errors were encountered: