Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file_get_contents timeout? 1

Status
Not open for further replies.

danomac

IS-IT--Management
Aug 2, 2002
731
0
16
AM
I looked around for an answer in the online manual for this, but didn't find one.

Will file_get_contents eventually time out and return false when working with external addresses? (ie http:/test/me.txt )

Thanks

Daniel
 
are you asking this for if a file does not exist or if it is a large file? if (1) file does not exist then you will get an error. if (2) there does not appear to be a timeout on it. I have done a quick search and there is nothing mentioned about a timeout though i suspect the page run time will affect the function.
 
I am referring to when the file doesn't exist *or* when for example, the remote server is busy and fails to respond with a 10060 (timeout).

I'm trying to write a script to get stats hourly from other websites, so if the script itself times out it wouldn't be very good, as some may remain unprocessed. And I can't find anything to set a connection timeout (in my case if it doesn't respond in say ~15 seconds I can skip it and go on to the next one.

I more or less have the script itself done, other than this timeout issue.

D
 
Identical to file(), except that file_get_contents() returns the file in a string. On failure, file_get_contents() will return FALSE

from this i read if the file exists it will be read into a string variable otherwise the result will be false so i might use something like:

... code to define file, open it and try to read it ....
if ($file_content <> "false")
{ perform additional code }

hope this helps. i may be wrong as have not tried to do anything like this.
 
Yeah, that's what I'm doing, but I am wondering if I can change the timeout value.

Anyone else know?
 
got this from the devshed forum.
<?php
if ($fp = @fsockopen($host, 80, $errno, $errstr, 10))
{
echo "Website is online!";
fclose($fp);
}
else
{
echo "Website is offline!";
}
?>

this checks if the server is there, then you would be able to get the file. can't see any way to get the file_get_contents timeout changed
 
I've never used the functions but would cURL help here ? or if your comfortable with the fsockopen read from it as well.
 
I think I will have to use fsockopen to check to see if the website is up, at least that way I can set a timeout.

I might have to also incorporate a retries type of feature to so if it fails to connect "x" amount of times it just ignores it in the future.

Thanks for the replies! php.net was real vague about timeouts and file_get_contents.

D
 
I'm doing some file reading on remote using a file function for php but i dont know where to get the timeout or if its possible to set its timeout. Does anybody know this issue.. thanks

Francis
 
crazyboy
Post a new thread. It will get you more answers....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top