T-Bird Posted April 23, 2009 Share Posted April 23, 2009 Alright, I'm at a loss as to what my problem is. I have a server box running Apache, PHP, and MySQL. This box contians a php file called passfile.php with the following code. <?php include('inc/function.inc.php'); $file = verify_file($_GET['file']); if($file != false) { header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.basename($file).'"'); readfile('http://MyFileHostExternalIP:880/bids/plans'.$file); } else { plans_error("<h3>Error: Requested File Not Found</h3>"); } ?> This works great. Now when I put this same php file, on my webhost and try to stream said file through my webpage to the user (so that I can better secure my files) I get the following error. Warning: readfile(http://MyFileServerExternalIP:880/bids/plans/ToC/a.txt) [function.readfile]: failed to open stream: Connection timed out in <b>/data/18/1/148/115/1800115/user/1948901/htdocs/estimating/passfile.php on line 8 Any ideas what I'm doing wrong. Why can readfile access the file when launched from my local box, but not when launched from my webhost? Is it an incorrect configuration? Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/ Share on other sites More sharing options...
schilly Posted April 23, 2009 Share Posted April 23, 2009 Most likely a permission error. http://ca2.php.net/manual/en/function.readfile.php Tip A URL can be used as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and List of Supported Protocols/Wrappers for a list of supported URL protocols. Check your server php.ini and look for the allow_url_fopen setting. Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-817082 Share on other sites More sharing options...
T-Bird Posted April 23, 2009 Author Share Posted April 23, 2009 Yeah. That was one of the first places I checked. When I first posted I was sure it was a php error, however as I look at it I think it could possibly be an Apache configuration problem as well. I'm lost on this one. A readfile download doesn't use a seperate port I'd have to forward does it? Doesn't it go through whatever port I'm sending the rest of the page through? Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-817098 Share on other sites More sharing options...
schilly Posted April 23, 2009 Share Posted April 23, 2009 A readfile download doesn't use a seperate port I'd have to forward does it? Doesn't it go through whatever port I'm sending the rest of the page through? I'm not sure. The only time I've loaded external files was through curl. Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-817373 Share on other sites More sharing options...
T-Bird Posted April 24, 2009 Author Share Posted April 24, 2009 If it at all helps anyone to grasp what's going on here, I drew a diagram. The red path is the one that ultimately I will be using and that is not working. The guest's node will connect to the passfile.php page of my webhost. Passfile.php holds the previously mentioned code which attempts to connect to my fileserver via a direct ip address:port - 70.166.xxx.xxx:880. It is supposed to use readfile() to make that connection and return the file contents from file.zip. However it gives me a connection timeout error. In blue was a test a ran to check the configuration status of my fileserver. When the server locally runs passfile.php which is identical - including using a full external ip instead of an alias like localhost, the file is returned properly. In green is a third test, where guest uses the fileserver's passfile.php to successfully retrieve file.zip. In purple was a forth test, whereby the guest direct connects to file.zip and successfully retrieves it. In cyan is a fifth test where guest connects to passfile.php on the webhost which is using identical code to test one except the IP is changed to another server I rent from bluehost. This is why I'm so baffled. Test five shows it cannot be an error with the php configuration on my webhost - for example allow_url_fopen must be on as it allows me to retrieve the file from my other server. It would seem to me that tests 2-4 indicate I have no leeching protection as both an arbitrary outside user as well as internal scripts both freely access the file. I cannot fathom what the actual problem must be. Any/all advice for further tests or fixes is gratefully accepted. Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-818673 Share on other sites More sharing options...
T-Bird Posted April 25, 2009 Author Share Posted April 25, 2009 More information that may or may not help. fopen and file_get_contents time out as well. cURL gives me error #7. I can't believe with everything I've tried we still haven't fixed it... Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-819277 Share on other sites More sharing options...
epilator Posted June 1, 2009 Share Posted June 1, 2009 if i see correctly, you're connecting to port 880. try connecting to the standard port 80, i just tried with my networksolutions account, and i can successfully connect to port 80, but not for example to port 2222, which gives a timeout. Link to comment https://forums.phpfreaks.com/topic/155280-readfile-connection-timeout-external-file/#findComment-846976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.