2016-03-28 11:19 GMT-05:00 Dan Ackroyd <dan...@basereality.com>:
> On 28 March 2016 at 02:57, Grzegorz Zdanowski <grzegorz...@gmail.com> wrote:
>>  by „gone away“
>> I mean some underlying error like forceful close of FD and not a
>> standard disconnection
>> of the client.
>
> What problem exactly are you trying to solve, and do you have a way of
> showing the problem that isn't just what looks like a programming
> mistake?

You're missing one point - the native file descriptor living inside a
kernel and somewhat
managed by PHP C code can change it's state independently from PHP knowledge.
The problem is stream resource is only an loosely representation of
native FD, not an
actual file descriptor.
TBH I don't know any way to damage the actual FD by programmer mistake in PHP.

I came across the problem in real environment in two cases:
1. Socket was listening with some specific IP and network card gone
away. Every call
to stream_select() produced situation described in OP and send the
code into dead-loop.
2. Using hardware-dependent socket (like ttys to USB<>RS232 converters) you can
trigger such error by simply disconnecting the USB cord (not always,
because some
drivers will just trigger EOF on socket and close it gracefully).

> e.g. The following code works fine. The file being closed doesn't
> affect the filehandle
>
> $fileHandle = fopen('foo.txt', 'r+');
> unlink('foo.txt');
> $data = fread($fileHandle, 20);
It's perfectly understandable - files have nothing to do with file
descriptors opened for
them.

> The following code doesn't work fine. The filehandle being closed,
> surprisingly enough, makes it not usable any more:
>
> $fileHandle = fopen('foo.txt', 'r+');
> fclose($fileHandle);
> $data = fread($fileHandle, 20);
Yes, that's true - after you call fclose() PHP gracefully closes the
socket and marks
the memory, so $fileHandle will no longer be a valid stream resource.


> So I don't understand what problem you're trying to analyze, other
> than closed file descriptors are closed.
If the socket was properly closed there's no discussion - you deal
with thousand times
a day, but the problem comes when the underlying FD will gone away.

Actually I found in C you can just call fcntl(FD, F_GETFD) and you'll
get -1 if given FD is
no longer valid FD. In PHP there's no way to do it - that's my problem.


---
Greg 'aka kiler129

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

Reply via email to