views:

37

answers:

2

I'm having a problem with PHP where i'm writing to a file very often, and sometimes it takes a long time to open that file. The complete description is here:

http://stackoverflow.com/questions/3759345/fopen-file-locking-in-php-reader-writer-type-of-situation

My question is how can I get fopen to timeout in, say, 50ms. I looked at stream-context-create but that seems to be for HTTP, or at least, if it'll work for local files, I'm not sure how to specify the option in the array.

Any ideas?

Thank you!
Daniel

+2  A: 

I'm not sure what you're trying here, but in some platforms (not Windows, though), you can open a file in non-blocking mode with the n flag:

$f = fopen("/tmp/foo/bar", "wn+");

This should return immediately. You can then probably use stream_select with a timeout of 50 ms.

I say "probably" because this flag is not documented.

Artefacto
@downvoter: Care to explain?
Artefacto
A: 

changing the default_socket_timeout variable in the php.ini to '1', would that helps?

ESCOBAR