Hello!

During refactoring of one of my server projects written in PHP I was
curious what PHP
will do if one of FDs given to stream_select() will gone away. Of
course by „gone away“
I mean some underlying error like forceful close of FD and not a
standard disconnection
of the client.

I did some tests, read documentation for select() call, dig into both
kernel & PHP sources
and I came to conclusion that there’s no way to cleanly recover from
stream_select() error :(
It's also worth to mention PHP displays E_WARNING with error, but
there's no clean
way to determine actual error.

I wrote simple test code: http://pastebin.com/6ws1xp5q
After running it one of it's sockets need to be killed. The easiest
way is to use
gdb on linux:
1. gdb -p PID
2. call close(3) //it will kill listener
3. q
4. y

After such sequence stream_select() will return false and all arrays
will stay unmodified.
Also as I mentioned before "PHP Warning:  stream_select(): unable to
select [9]: Bad
file descriptor (max_fd=4)" will be triggered.

I tried is_resource(), fread(), stream_get_meta_data(), feof() - none
of them are giving
me any clues which socket errored.
Killing whole server on single socket error is not an option for me.

Is there any (even crazy) way to determine which socket is considered bad?



p.s. I found similar problem regarding C on SO, but they didn't found
a good solution:
http://stackoverflow.com/questions/12838041/method-to-handle-bad-file-descriptor-error

---
Greg 'aka kiler129

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to