Since I still cannot comment (and editing or flagging the question (as a duplicate(?)) probably is not quite appropriate in this case), let me add a follow-up question, and a comment as an answer:
- When you said:
I assigned a small value to the timeout and in spite of this file_get_contents returns the good result
Do you mean that even if you set a time-out of, say, 1 second, file_get_contents() takes more that that, and doesn't time out? Do you have any low level monitoring available to distinguish the time it takes to "connect", and "read" data?
- Because as Fanis said in his answer to question "PHP file_get_contents ignoring timeout?", if you're using "file_get_contents()" (and not lower level socket functions), the time to "connect" to the remote server cannot be set by the available ini setting, or the context entry apparently. You only set the "read" time out by those.
(I realize this is an old question but, I ran into these 2 in my searches as I had the same question, and thought I should set up the link between them)